Skip to content

Commit

Permalink
find_base_name will not prepend builtins for builtin names
Browse files Browse the repository at this point in the history
  • Loading branch information
andrecsilva committed Jan 10, 2024
1 parent 269469d commit d913be5
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/codemodder/codemods/utils_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 0 additions & 2 deletions src/codemodder/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__}"


Expand Down
4 changes: 1 addition & 3 deletions src/core_codemods/remove_debug_breakpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
4 changes: 2 additions & 2 deletions tests/test_nameresolution_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d913be5

Please sign in to comment.