Skip to content

Commit

Permalink
path_to_root should not include original node
Browse files Browse the repository at this point in the history
  • Loading branch information
clavedeluna committed Mar 13, 2024
1 parent 7f5d2ca commit e6f08fe
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/codemodder/codemods/utils_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,10 @@ def find_immediate_class_def(self, node: cst.CSTNode) -> Optional[cst.ClassDef]:

def path_to_root(self, node: cst.CSTNode) -> list[cst.CSTNode]:
"""
Returns node's path to root. Includes self.
Returns node's path to `node` (excludes `node`).
"""
path = []
maybe_parent = node
maybe_parent = self.get_parent(node)
while maybe_parent:
path.append(maybe_parent)
maybe_parent = self.get_parent(maybe_parent)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ancestorpatterns_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def transform_module_impl(self, tree: cst.Module) -> cst.Module:
node = stmt.body[0]

path = self.path_to_root(node)
assert len(path) == 3
assert len(path) == 2
return tree

input_code = dedent(
Expand Down

0 comments on commit e6f08fe

Please sign in to comment.