Skip to content

Commit

Permalink
Merge pull request #634 from python-rope/remove-non-recursive-call-fo…
Browse files Browse the repository at this point in the history
…r-nodes

Remove call_for_nodes(recursive) argument
  • Loading branch information
lieryan committed Jan 3, 2023
2 parents f6ad157 + ef28b09 commit d05424b
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- #611 Implement JSON DataFile serialization (@lieryan)
- #630 SQLite models improvements (@lieryan)
- #631 Implement version hash (@lieryan)
- #634 Remove call_for_nodes(recursive) argument (@edreamleo)


# Release 1.6.0
Expand Down
6 changes: 3 additions & 3 deletions rope/base/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ def parse(source, filename="<string>", *args, **kwargs): # type: ignore
raise error


def call_for_nodes(node, callback, recursive=False):
def call_for_nodes(node, callback):
"""If callback returns `True` the child nodes are skipped"""
result = callback(node)
if recursive and not result:
if not result:
for child in ast.iter_child_nodes(node):
call_for_nodes(child, callback, recursive)
call_for_nodes(child, callback)


class RopeNodeVisitor(ast.NodeVisitor):
Expand Down
4 changes: 2 additions & 2 deletions rope/refactor/patchedast.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def patch_ast(node, source, sorted_children=False):
if hasattr(node, "region"):
return node
walker = _PatchingASTWalker(source, children=sorted_children)
ast.call_for_nodes(node, walker)
walker(node)
return node


Expand Down Expand Up @@ -110,7 +110,7 @@ def _handle(self, node, base_children, eat_parens=False, eat_spaces=False):
continue
offset = self.source.offset
if isinstance(child, ast.AST):
ast.call_for_nodes(child, self)
self(child)
token_start = child.region[0]
else:
if child is self.String:
Expand Down
2 changes: 1 addition & 1 deletion rope/refactor/similarfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def __init__(self, body, pattern, does_match):
def find_matches(self):
if self.matches is None:
self.matches = []
ast.call_for_nodes(self.body, self._check_node, recursive=True)
ast.call_for_nodes(self.body, self._check_node)
return self.matches

def _check_node(self, node):
Expand Down
2 changes: 1 addition & 1 deletion ropetest/refactor/patchedasttest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,7 @@ def __call__(self, node):
return self.result is not None

search = Search()
ast.call_for_nodes(self.ast, search, recursive=True)
ast.call_for_nodes(self.ast, search)
return search.result

def check_children(self, text, children):
Expand Down

0 comments on commit d05424b

Please sign in to comment.