Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-101517: Attach line number to the RERAISE at the end of a try-except* #101768

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_sys_settrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,7 @@ def func():
(3, 'line'),
(3, 'exception'),
(4, 'line'),
(4, 'line'),
(6, 'line'),
(7, 'line'),
(7, 'return')])
Expand All @@ -1440,6 +1441,7 @@ def func():
(3, 'line'),
(3, 'exception'),
(4, 'line'),
(4, 'line'),
(6, 'line'),
(7, 'line'),
(7, 'return')])
Expand Down Expand Up @@ -1481,6 +1483,7 @@ def func():
(8, 'line'),
(10, 'line'),
(11, 'line'),
(10, 'line'),
(12, 'line'),
(13, 'line'),
(14, 'line'),
Expand Down
9 changes: 2 additions & 7 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down