Skip to content

Construct ast node with known fields to avoid deprecation warning in Python 3.13 #90

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

Merged
Changes from all commits
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
16 changes: 9 additions & 7 deletions gast/astn.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ def _visit(self, node):
return node

def generic_visit(self, node):
cls = type(node).__name__
try:
new_node = getattr(to, cls)()
except AttributeError:
class_name = type(node).__name__
if not hasattr(to, class_name):
# handle nodes that are not part of the AST
return

for field in node._fields:
setattr(new_node, field, self._visit(getattr(node, field)))
cls = getattr(to, class_name)
new_node = cls(
**{
field: self._visit(getattr(node, field))
for field in node._fields
}
)

for attr in node._attributes:
try:
Expand Down
Loading