From d913be526ff57199f783ebfdf9ac86bca18d51b1 Mon Sep 17 00:00:00 2001 From: andrecs <12188364+andrecsilva@users.noreply.github.com> Date: Wed, 10 Jan 2024 09:16:09 -0300 Subject: [PATCH] find_base_name will not prepend builtins for builtin names --- src/codemodder/codemods/utils_mixin.py | 3 +++ src/codemodder/utils/utils.py | 2 -- src/core_codemods/remove_debug_breakpoint.py | 4 +--- tests/test_nameresolution_mixin.py | 4 ++-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/codemodder/codemods/utils_mixin.py b/src/codemodder/codemods/utils_mixin.py index 3c80ca599..42d1a1538 100644 --- a/src/codemodder/codemods/utils_mixin.py +++ b/src/codemodder/codemods/utils_mixin.py @@ -35,6 +35,9 @@ def _find_imported_name(self, node: cst.Name): alias.evaluated_name, ): return self.base_name_for_import(import_node, alias) + case BuiltinAssignment(): + return "builtins." + node.value + return node.value def find_base_name(self, node): diff --git a/src/codemodder/utils/utils.py b/src/codemodder/utils/utils.py index 7c8732d15..4b936c2f6 100644 --- a/src/codemodder/utils/utils.py +++ b/src/codemodder/utils/utils.py @@ -14,8 +14,6 @@ def list_subclasses(base_kls) -> set[str]: def full_qualified_name_from_class(cls) -> str: - if cls.__module__ == "builtins": - return cls.__qualname__ return f"{cls.__module__}.{cls.__qualname__}" diff --git a/src/core_codemods/remove_debug_breakpoint.py b/src/core_codemods/remove_debug_breakpoint.py index 104dcb07a..7a35846f7 100644 --- a/src/core_codemods/remove_debug_breakpoint.py +++ b/src/core_codemods/remove_debug_breakpoint.py @@ -21,9 +21,7 @@ def leave_Expr( match call_node := original_node.value: case cst.Call(): - if self.find_base_name( - call_node - ) == "breakpoint" and self.is_builtin_function(call_node): + if self.find_base_name(call_node) == "builtins.breakpoint": self.report_change(original_node) return cst.RemovalSentinel.REMOVE if self.find_base_name(call_node) == "pdb.set_trace": diff --git a/tests/test_nameresolution_mixin.py b/tests/test_nameresolution_mixin.py index 9208b00b1..c8b519cd0 100644 --- a/tests/test_nameresolution_mixin.py +++ b/tests/test_nameresolution_mixin.py @@ -92,12 +92,12 @@ def transform_module_impl(self, tree: cst.Module) -> cst.Module: node = expr.value maybe_name = self.find_base_name(node.func) - assert maybe_name == "exec.capitalize" + assert maybe_name == "builtins.print" return tree input_code = dedent( """\ - exec.capitalize() + print('hello world') """ ) tree = cst.parse_module(input_code)