@@ -279,12 +279,8 @@ def __or__(self, other: Pattern) -> AnyOf:
279
279
-------
280
280
New pattern that matches if either of the patterns match.
281
281
"""
282
- if isinstance (self , AnyOf ) and isinstance (other , AnyOf ):
283
- return AnyOf (* self .inners , * other .inners )
284
- elif isinstance (self , AnyOf ):
285
- return AnyOf (* self .inners , other )
286
- elif isinstance (other , AnyOf ):
287
- return AnyOf (self , * other .inners )
282
+ if isinstance (other , AnyOf ):
283
+ return AnyOf (self , * cython .cast (AnyOf , other ).inners )
288
284
else :
289
285
return AnyOf (self , other )
290
286
@@ -300,12 +296,8 @@ def __and__(self, other: Pattern) -> AllOf:
300
296
-------
301
297
New pattern that matches if both of the patterns match.
302
298
"""
303
- if isinstance (self , AllOf ) and isinstance (other , AllOf ):
304
- return AllOf (* self .inners , * other .inners )
305
- elif isinstance (self , AllOf ):
306
- return AllOf (* self .inners , other )
307
- elif isinstance (other , AllOf ):
308
- return AllOf (self , * other .inners )
299
+ if isinstance (other , AllOf ):
300
+ return AllOf (self , * cython .cast (AllOf , other ).inners )
309
301
else :
310
302
return AllOf (self , other )
311
303
@@ -883,6 +875,23 @@ def match(self, value, ctx: Context):
883
875
pass
884
876
raise NoMatchError ()
885
877
878
+ def __or__ (self , other : Pattern ) -> AnyOf :
879
+ """Syntax sugar for matching either of the patterns.
880
+
881
+ Parameters
882
+ ----------
883
+ other
884
+ The other pattern to match against.
885
+
886
+ Returns
887
+ -------
888
+ New pattern that matches if either of the patterns match.
889
+ """
890
+ if isinstance (other , AnyOf ):
891
+ return AnyOf (* self .inners , * cython .cast (AnyOf , other ).inners )
892
+ else :
893
+ return AnyOf (* self .inners , other )
894
+
886
895
887
896
@cython .final
888
897
@cython .cclass
@@ -905,6 +914,23 @@ def match(self, value, ctx: Context):
905
914
value = inner .match (value , ctx )
906
915
return value
907
916
917
+ def __and__ (self , other : Pattern ) -> AllOf :
918
+ """Syntax sugar for matching both of the patterns.
919
+
920
+ Parameters
921
+ ----------
922
+ other
923
+ The other pattern to match against.
924
+
925
+ Returns
926
+ -------
927
+ New pattern that matches if both of the patterns match.
928
+ """
929
+ if isinstance (other , AllOf ):
930
+ return AllOf (* self .inners , * cython .cast (AllOf , other ).inners )
931
+ else :
932
+ return AllOf (* self .inners , other )
933
+
908
934
909
935
def NoneOf (* args ) -> Pattern :
910
936
"""Match none of the passed patterns."""
0 commit comments