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

Prepend builtins base name #209

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

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