Skip to content

Commit

Permalink
Disallow renaming for non-local names used in class scope in store co…
Browse files Browse the repository at this point in the history
…ntext

They create a new binding in the class namespace
  • Loading branch information
dflook committed Aug 9, 2024
1 parent 194b5fc commit 1bec27f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/python_minifier/rename/resolve_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ def resolve_names(node):
if isinstance(node, ast.Name) and isinstance(node.ctx, ast.Load):
get_binding(node.id, node.namespace).add_reference(node)
elif isinstance(node, ast.Name) and node.id in node.namespace.nonlocal_names:
get_binding(node.id, node.namespace).add_reference(node)
binding = get_binding(node.id, node.namespace)
binding.add_reference(node)

if isinstance(node.ctx, ast.Store) and isinstance(node.namespace, ast.ClassDef):
binding.disallow_rename()

elif isinstance(node, ast.ClassDef) and node.name in node.namespace.nonlocal_names:
get_binding(node.name, node.namespace).add_reference(node)
Expand Down

0 comments on commit 1bec27f

Please sign in to comment.