Skip to content

Commit

Permalink
fix else after except*
Browse files Browse the repository at this point in the history
  • Loading branch information
cfbolz committed Sep 25, 2024
1 parent 3fef457 commit 3570f41
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pypy/interpreter/astcompiler/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 17 additions & 0 deletions pypy/interpreter/astcompiler/test/apptest_exceptiongroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


0 comments on commit 3570f41

Please sign in to comment.