Skip to content

Commit

Permalink
fix bug in rename: rename also in global and nonlocal decls
Browse files Browse the repository at this point in the history
  • Loading branch information
Technologicat committed Sep 27, 2024
1 parent 3e19ffd commit 6646a85
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
**Fixed**:

- Fix https://github.com/Technologicat/mcpyrate/issues/41. The unparser now understands the Python 3.10 pattern matching construct `match`/`case`.
- Fix bug in `rename`: rename also in `global` and `nonlocal` declarations.


---
Expand Down
4 changes: 4 additions & 0 deletions mcpyrate/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ def transform(self, tree):
elif T is ast.ExceptHandler:
if tree.name == oldname:
tree.name = newname
elif T in (ast.Global, ast.Nonlocal):
for j in range(len(tree.names)):
if tree.names[j] == oldname:
tree.names[j] = newname
return self.generic_visit(tree)
return Renamer().visit(tree)

Expand Down

0 comments on commit 6646a85

Please sign in to comment.