@@ -527,7 +527,7 @@ def check_union(tp, pattern_args):
527527 except TypeError as e :
528528 reasons .append (e )
529529 else :
530- reasons = None
530+ reasons = []
531531 break
532532 if self .match_any_of_union and len (reasons ) < len (tp_args ):
533533 # Just need one of the union args to match
@@ -1122,16 +1122,42 @@ def is_fileset_or_union(type_: type, allow_none: bool | None = None) -> bool:
11221122 is_fileset : bool
11231123 whether the type is a FileSet or a Union containing a FileSet
11241124 """
1125+ return is_subclass_or_union (type_ , core .FileSet , allow_none = allow_none )
1126+
1127+
1128+ def is_subclass_or_union (
1129+ type_ : type , reference : type , allow_none : bool | None = None
1130+ ) -> bool :
1131+ """Check if the type is a subclass of given reference or a Union containing
1132+ that reference type
1133+
1134+ Parameters
1135+ ----------
1136+ type_ : type
1137+ the type to check
1138+ reference : type
1139+ the reference type to check whether the type is a sub-class of or not
1140+ allow_none : bool, optional
1141+ whether to allow None as a valid type, by default None. If None, then None
1142+ is not allowed at the outer layer, but is allowed within a Union
1143+
1144+ Returns
1145+ -------
1146+ bool
1147+ whether the type is a FileSet or a Union containing a FileSet
1148+ """
11251149 if type_ is None and allow_none :
11261150 return True
11271151 if is_union (type_ ):
11281152 return any (
1129- is_fileset_or_union (t , allow_none = allow_none or allow_none is None )
1153+ is_subclass_or_union (
1154+ t , reference , allow_none = allow_none or allow_none is None
1155+ )
11301156 for t in ty .get_args (type_ )
11311157 )
11321158 elif not inspect .isclass (type_ ):
11331159 return False
1134- return issubclass (type_ , core . FileSet )
1160+ return issubclass (type_ , reference )
11351161
11361162
11371163def is_type (* args : ty .Any ) -> bool :
0 commit comments