From e6f08fe84ee0b88c144e242479feda3c263fd1e0 Mon Sep 17 00:00:00 2001 From: clavedeluna Date: Wed, 13 Mar 2024 11:40:09 -0300 Subject: [PATCH] `path_to_root` should not include original node --- src/codemodder/codemods/utils_mixin.py | 4 ++-- tests/test_ancestorpatterns_mixin.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/codemodder/codemods/utils_mixin.py b/src/codemodder/codemods/utils_mixin.py index 4e7cfe757..a7876a003 100644 --- a/src/codemodder/codemods/utils_mixin.py +++ b/src/codemodder/codemods/utils_mixin.py @@ -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) diff --git a/tests/test_ancestorpatterns_mixin.py b/tests/test_ancestorpatterns_mixin.py index ba86e824d..8c683b6e3 100644 --- a/tests/test_ancestorpatterns_mixin.py +++ b/tests/test_ancestorpatterns_mixin.py @@ -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(