Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove call_for_nodes(recursive) argument #634

Merged
merged 3 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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