diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 48f419e62fbbed..19de501a7b9866 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -1408,6 +1408,28 @@ def test_pdb_issue_gh_91742(): Author: 'pi' Version: '3.14' """ +def test_pdb_issue_gh_101517(): + """See GH-101517 + + breakpoint in except* clause + + >>> def test_function(): + ... try: + ... raise ExceptionGroup("eg", [KeyError(), ValueError()]) + ... except* KeyError: + ... breakpoint() + ... + >>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE + ... 'continue' + ... ]): + ... try: + ... test_function() + ... except Exception as e: + ... print(repr(e)) + ExceptionGroup('eg', [ValueError()]) + >>> + """ + def test_pdb_issue_gh_94215(): """See GH-94215 diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py index a251b2272e95eb..27266e2c1f1421 100644 --- a/Lib/test/test_sys_settrace.py +++ b/Lib/test/test_sys_settrace.py @@ -1418,6 +1418,7 @@ def func(): (3, 'line'), (3, 'exception'), (4, 'line'), + (4, 'line'), (6, 'line'), (7, 'line'), (7, 'return')]) @@ -1440,6 +1441,7 @@ def func(): (3, 'line'), (3, 'exception'), (4, 'line'), + (4, 'line'), (6, 'line'), (7, 'line'), (7, 'return')]) @@ -1481,6 +1483,7 @@ def func(): (8, 'line'), (10, 'line'), (11, 'line'), + (10, 'line'), (12, 'line'), (13, 'line'), (14, 'line'), diff --git a/Python/compile.c b/Python/compile.c index df2dffb95bbd7e..359a0dd1f42644 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -3633,7 +3633,6 @@ compiler_try_star_except(struct compiler *c, stmt_ty s) NEW_JUMP_TARGET_LABEL(c, orelse); NEW_JUMP_TARGET_LABEL(c, end); NEW_JUMP_TARGET_LABEL(c, cleanup); - NEW_JUMP_TARGET_LABEL(c, reraise_star); ADDOP_JUMP(c, loc, SETUP_FINALLY, except); @@ -3659,7 +3658,7 @@ compiler_try_star_except(struct compiler *c, stmt_ty s) for (Py_ssize_t i = 0; i < n; i++) { excepthandler_ty handler = (excepthandler_ty)asdl_seq_GET( s->v.TryStar.handlers, i); - location loc = LOC(handler); + loc = LOC(handler); NEW_JUMP_TARGET_LABEL(c, next_except); except = next_except; NEW_JUMP_TARGET_LABEL(c, handle_match); @@ -3745,21 +3744,17 @@ compiler_try_star_except(struct compiler *c, stmt_ty s) /* add exception raised to the res list */ ADDOP_I(c, NO_LOCATION, LIST_APPEND, 3); // exc ADDOP(c, NO_LOCATION, POP_TOP); // lasti - ADDOP_JUMP(c, NO_LOCATION, JUMP, except); USE_LABEL(c, except); - if (i == n - 1) { /* Add exc to the list (if not None it's the unhandled part of the EG) */ ADDOP_I(c, NO_LOCATION, LIST_APPEND, 1); - ADDOP_JUMP(c, NO_LOCATION, JUMP, reraise_star); } } /* artificial */ compiler_pop_fblock(c, EXCEPTION_GROUP_HANDLER, NO_LABEL); NEW_JUMP_TARGET_LABEL(c, reraise); - USE_LABEL(c, reraise_star); ADDOP(c, NO_LOCATION, PREP_RERAISE_STAR); ADDOP_I(c, NO_LOCATION, COPY, 1); ADDOP_JUMP(c, NO_LOCATION, POP_JUMP_IF_NOT_NONE, reraise); @@ -3774,7 +3769,7 @@ compiler_try_star_except(struct compiler *c, stmt_ty s) ADDOP(c, NO_LOCATION, POP_BLOCK); ADDOP_I(c, NO_LOCATION, SWAP, 2); ADDOP(c, NO_LOCATION, POP_EXCEPT); - ADDOP_I(c, NO_LOCATION, RERAISE, 0); + ADDOP_I(c, loc, RERAISE, 0); USE_LABEL(c, cleanup); POP_EXCEPT_AND_RERAISE(c, NO_LOCATION);