diff --git a/astroid/rebuilder.py b/astroid/rebuilder.py index 9ac9c7eb4f..0994cfd678 100644 --- a/astroid/rebuilder.py +++ b/astroid/rebuilder.py @@ -1823,13 +1823,20 @@ def visit_try( return None def visit_trystar(self, node: ast.TryStar, parent: NodeNG) -> nodes.TryStar: - return nodes.TryStar( + newnode = nodes.TryStar( lineno=node.lineno, col_offset=node.col_offset, end_lineno=getattr(node, "end_lineno", None), end_col_offset=getattr(node, "end_col_offset", None), parent=parent, ) + newnode.postinit( + body=[self.visit_tryexcept(node, newnode)], + handlers=[self.visit(n, newnode) for n in node.handlers], + orelse=[self.visit(n, newnode) for n in node.orelse], + finalbody=[self.visit(n, newnode) for n in node.finalbody], + ) + return newnode def visit_tuple(self, node: ast.Tuple, parent: NodeNG) -> nodes.Tuple: """Visit a Tuple node by returning a fresh instance of it.""" diff --git a/tests/test_group_exceptions.py b/tests/test_group_exceptions.py index b01c860140..994658f5a6 100644 --- a/tests/test_group_exceptions.py +++ b/tests/test_group_exceptions.py @@ -44,4 +44,4 @@ def test_star_exceptions() -> None: assert node.handlers handler = node.handlers[0] assert isinstance(handler, ExceptHandler) - assert handler.type.name == "ExceptionGroup" + assert handler.type.name == "ValueError"