Skip to content

Commit 5818f35

Browse files
committed
Initialize ast node with known fields to avoid deprecation warning in Python 3.13
1 parent b4d2df6 commit 5818f35

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

gast/astn.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ def _visit(self, node):
1515
return node
1616

1717
def generic_visit(self, node):
18-
cls = type(node).__name__
19-
try:
20-
new_node = getattr(to, cls)()
21-
except AttributeError:
18+
class_name = type(node).__name__
19+
if not hasattr(to, class_name):
2220
# handle nodes that are not part of the AST
2321
return
24-
25-
for field in node._fields:
26-
setattr(new_node, field, self._visit(getattr(node, field)))
22+
cls = getattr(to, class_name)
23+
new_node = cls(
24+
**{
25+
field: self._visit(getattr(node, field))
26+
for field in node._fields
27+
}
28+
)
2729

2830
for attr in node._attributes:
2931
try:

0 commit comments

Comments
 (0)