| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -555,15 +555,26 @@ def visit_For(self, node): | |||
| 555 | 555 | path=self.filenames[-1] | |
| 556 | 556 | )) | |
| 557 | 557 | ||
| 558 | - if isinstance(node.iter, ast.Call) and get_call_names_as_string(node.iter.func) in self.function_names: | ||
| 559 | - last_node = self.visit(node.iter) | ||
| 560 | - last_node.connect(for_node) | ||
| 558 | + self.process_loop_funcs(node.iter, for_node) | ||
| 561 | 559 | ||
| 562 | 560 | return self.loop_node_skeleton(for_node, node) | |
| 563 | 561 | ||
| 562 | + def process_loop_funcs(self, comp_n, loop_node): | ||
| 563 | + """ | ||
| 564 | + If the loop test node contains function calls, it connects the loop node to the nodes of | ||
| 565 | + those function calls. | ||
| 566 | + | ||
| 567 | + :param comp_n: The test node of a loop that may contain functions. | ||
| 568 | + :param loop_node: The loop node itself to connect to the new function nodes if any | ||
| 569 | + :return: None | ||
| 570 | + """ | ||
| 571 | + if isinstance(comp_n, ast.Call) and get_call_names_as_string(comp_n.func) in self.function_names: | ||
| 572 | + last_node = self.visit(comp_n) | ||
| 573 | + last_node.connect(loop_node) | ||
| 574 | + | ||
| 564 | 575 | def visit_While(self, node): | |
| 565 | 576 | label_visitor = LabelVisitor() | |
| 566 | - test = node.test # the test condition of the while loop | ||
| 577 | + test = node.test # the test condition of the while loop | ||
| 567 | 578 | label_visitor.visit(test) | |
| 568 | 579 | ||
| 569 | 580 | while_node = self.append_node(Node( | |
@@ -572,19 +583,14 @@ def visit_While(self, node): | |||
| 572 | 583 | path=self.filenames[-1] | |
| 573 | 584 | )) | |
| 574 | 585 | ||
| 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) | ||
| 578 | - last_node.connect(while_node) | ||
| 579 | - | ||
| 580 | 586 | if isinstance(test, ast.Compare): | |
| 581 | 587 | comparators = test.comparators | |
| 582 | - comparators.append(test.left) # quirk. See https://greentreesnakes.readthedocs.io/en/latest/nodes.html#Compare | ||
| 588 | + comparators.append(test.left) # quirk. See https://greentreesnakes.readthedocs.io/en/latest/nodes.html#Compare | ||
| 583 | 589 | ||
| 584 | 590 | for comp in comparators: | |
| 585 | - process_comparator(comp) | ||
| 586 | - else: # while foo(): | ||
| 587 | - process_comparator(test) | ||
| 591 | + self.process_loop_funcs(comp, while_node) | ||
| 592 | + else: # while foo(): | ||
| 593 | + self.process_loop_funcs(test, while_node) | ||
| 588 | 594 | ||
| 589 | 595 | return self.loop_node_skeleton(while_node, node) | |
| 590 | 596 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments