From 3570f41d35a37e4944ca2f2eee26f3b57e037940 Mon Sep 17 00:00:00 2001 From: CF Bolz-Tereick Date: Wed, 25 Sep 2024 11:32:30 +0200 Subject: [PATCH] fix else after except* --- pypy/interpreter/astcompiler/codegen.py | 2 +- .../astcompiler/test/apptest_exceptiongroup.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/pypy/interpreter/astcompiler/codegen.py b/pypy/interpreter/astcompiler/codegen.py index c2a435a0eb2..d7416023a02 100644 --- a/pypy/interpreter/astcompiler/codegen.py +++ b/pypy/interpreter/astcompiler/codegen.py @@ -1141,7 +1141,7 @@ def visit_TryStar(self, tr): self.emit_op(ops.POP_TOP) self.emit_op(ops.POP_EXCEPT) self.emit_op(ops.POP_TOP) # pypy difference: get rid of unroller - self.emit_jump(ops.JUMP_FORWARD, otherwise) + self.emit_jump(ops.JUMP_FORWARD, end) self.use_next_block(reraise_block) if handler is not None: diff --git a/pypy/interpreter/astcompiler/test/apptest_exceptiongroup.py b/pypy/interpreter/astcompiler/test/apptest_exceptiongroup.py index 76bb2aac469..84a90539d0b 100644 --- a/pypy/interpreter/astcompiler/test/apptest_exceptiongroup.py +++ b/pypy/interpreter/astcompiler/test/apptest_exceptiongroup.py @@ -84,4 +84,21 @@ def test_try_star_name_raise_in_except_handler(): with raises(UnboundLocalError): e1 +def maybe_raise_typeerror(x): + if x: + raise TypeError + +def try_except_star_with_else(x): + try: + maybe_raise_typeerror(x) + except* TypeError: + a = 1 + else: + a = 2 + return a + +def test_try_except_star_with_else(): + assert try_except_star_with_else(True) == 1 + assert try_except_star_with_else(False) == 2 +