Skip to content

Commit 6515118

Browse files
fixup! Visit child nodes of TryStar
1 parent b9f6379 commit 6515118

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

astroid/rebuilder.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1823,7 +1823,25 @@ def visit_try(
18231823
return None
18241824

18251825
def visit_trystar(self, node: ast.TryStar, parent: NodeNG) -> nodes.TryStar:
1826-
return self.visit_try(node, parent, newNodeClass=nodes.TryStar)
1826+
newnode = nodes.TryStar(
1827+
lineno=node.lineno,
1828+
col_offset=node.col_offset,
1829+
end_lineno=getattr(node, "end_lineno", None),
1830+
end_col_offset=getattr(node, "end_col_offset", None),
1831+
parent=parent,
1832+
)
1833+
body: list[NodeNG | nodes.TryExcept]
1834+
if node.handlers:
1835+
body = [self.visit_tryexcept(node, newnode)]
1836+
else:
1837+
body = [self.visit(child, newnode) for child in node.body]
1838+
newnode.postinit(
1839+
body=body,
1840+
handlers=[self.visit(n, newnode) for n in node.handlers],
1841+
orelse=[self.visit(n, newnode) for n in node.orelse],
1842+
finalbody=[self.visit(n, newnode) for n in node.finalbody],
1843+
)
1844+
return newnode
18271845

18281846
def visit_tuple(self, node: ast.Tuple, parent: NodeNG) -> nodes.Tuple:
18291847
"""Visit a Tuple node by returning a fresh instance of it."""

tests/test_group_exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ def test_star_exceptions() -> None:
4444
assert node.handlers
4545
handler = node.handlers[0]
4646
assert isinstance(handler, ExceptHandler)
47-
assert handler.type.name == "ExceptionGroup"
47+
assert handler.type.name == "ValueError"

0 commit comments

Comments
 (0)