@@ -527,7 +527,7 @@ def check_union(tp, pattern_args):
527
527
except TypeError as e :
528
528
reasons .append (e )
529
529
else :
530
- reasons = None
530
+ reasons = []
531
531
break
532
532
if self .match_any_of_union and len (reasons ) < len (tp_args ):
533
533
# 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:
1122
1122
is_fileset : bool
1123
1123
whether the type is a FileSet or a Union containing a FileSet
1124
1124
"""
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
+ """
1125
1149
if type_ is None and allow_none :
1126
1150
return True
1127
1151
if is_union (type_ ):
1128
1152
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
+ )
1130
1156
for t in ty .get_args (type_ )
1131
1157
)
1132
1158
elif not inspect .isclass (type_ ):
1133
1159
return False
1134
- return issubclass (type_ , core . FileSet )
1160
+ return issubclass (type_ , reference )
1135
1161
1136
1162
1137
1163
def is_type (* args : ty .Any ) -> bool :
0 commit comments