@@ -527,6 +527,9 @@ def __init__(self, mapping):
527
527
def _no_match (self , left , right ):
528
528
return False
529
529
530
+ def _all_match (self , lefts , rights ):
531
+ return len (lefts ) == len (rights ) and all (self ._match (left_ , right_ ) for left_ , right_ in zip (lefts , rights ))
532
+
530
533
def _match (self , left , right ):
531
534
same_ctx = not hasattr (right , "ctx" ) or getattr (left , "ctx" , None ).__class__ is right .ctx .__class__
532
535
cname = left .__class__ .__name__
@@ -565,20 +568,33 @@ def _match_Tuple(self, left, right):
565
568
return self ._match_List (left , right )
566
569
567
570
def _match_ListComp (self , left , right ):
568
- return (
569
- self ._match (left .elt , right .elt )
570
- and len (left .generators ) == len (right .generators )
571
- and all (self ._match (left_ , right_ ) for left_ , right_ in zip (left .generators , right .generators ))
572
- )
571
+ return self ._match (left .elt , right .elt ) and self ._all_match (left .generators , right .generators )
573
572
574
573
def _match_comprehension (self , left , right ):
575
574
return (
576
575
# async is not expected in our use cases, just for completeness
577
576
getattr (left , "is_async" , 0 ) == getattr (right , "is_async" , 0 )
578
- and len (left .ifs ) == len (right .ifs )
579
577
and self ._match (left .target , right .target )
580
578
and self ._match (left .iter , right .iter )
581
- and all (self ._match (left_ , right_ ) for left_ , right_ in zip (left .ifs , right .ifs ))
579
+ and self ._all_match (left .ifs , right .ifs )
580
+ )
581
+
582
+ def _match_BinOp (self , left , right ):
583
+ return (
584
+ left .op .__class__ is right .op .__class__
585
+ and self ._match (left .left , right .left )
586
+ and self ._match (left .right , right .right )
587
+ )
588
+
589
+ def _match_BoolOp (self , left , right ):
590
+ return left .op .__class__ is right .op .__class__ and self ._all_match (left .values , right .values )
591
+
592
+ def _match_Compare (self , left , right ):
593
+ return (
594
+ len (left .ops ) == len (right .ops )
595
+ and all (lop .__class__ is rop .__class__ for lop , rop in zip (left .ops , right .ops ))
596
+ and self ._match (left .left , right .left )
597
+ and self ._all_match (left .comparators , right .comparators )
582
598
)
583
599
584
600
def visit (self , node ):
0 commit comments