@@ -563,19 +563,29 @@ def visit_For(self, node):
563563
564564 def visit_While (self , node ):
565565 label_visitor = LabelVisitor ()
566- label_visitor .visit (node .test )
566+ test = node .test # the test condition of the while loop
567+ label_visitor .visit (test )
567568
568569 while_node = self .append_node (Node (
569570 'while ' + label_visitor .result + ':' ,
570571 node ,
571572 path = self .filenames [- 1 ]
572573 ))
573574
574- for comp in node . test . comparators :
575- if isinstance (comp , ast .Call ) and get_call_names_as_string (comp .func ) in self .function_names :
576- last_node = self .visit (comp )
575+ def process_comparator ( comp_n ) :
576+ if isinstance (comp_n , ast .Call ) and get_call_names_as_string (comp_n .func ) in self .function_names :
577+ last_node = self .visit (comp_n )
577578 last_node .connect (while_node )
578579
580+ if isinstance (test , ast .Compare ):
581+ comparators = test .comparators
582+ comparators .append (test .left ) # quirk. See https://greentreesnakes.readthedocs.io/en/latest/nodes.html#Compare
583+
584+ for comp in comparators :
585+ process_comparator (comp )
586+ else : # while foo():
587+ process_comparator (test )
588+
579589 return self .loop_node_skeleton (while_node , node )
580590
581591 def add_blackbox_or_builtin_call (self , node , blackbox ): # noqa: C901
0 commit comments