Skip to content

bpo-39114: Fix tracing of except handlers with name binding #17769

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

Merged
merged 2 commits into from
Jan 2, 2020
Merged
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
45 changes: 45 additions & 0 deletions Lib/test/test_sys_settrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,51 @@ def func():
[(0, 'call'),
(1, 'line')])

def test_18_except_with_name(self):
def func():
try:
try:
raise Exception
except Exception as e:
raise
x = "Something"
y = "Something"
except Exception:
pass

self.run_and_compare(func,
[(0, 'call'),
(1, 'line'),
(2, 'line'),
(3, 'line'),
(3, 'exception'),
(4, 'line'),
(5, 'line'),
(8, 'line'),
(9, 'line'),
(9, 'return')])

def test_19_except_with_finally(self):
def func():
try:
try:
raise Exception
finally:
y = "Something"
except Exception:
b = 23

self.run_and_compare(func,
[(0, 'call'),
(1, 'line'),
(2, 'line'),
(3, 'line'),
(3, 'exception'),
(5, 'line'),
(6, 'line'),
(7, 'line'),
(7, 'return')])


class SkipLineEventsTraceTestCase(TraceTestCase):
"""Repeat the trace tests, but with per-line events skipped"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix incorrent line execution reporting in trace functions when tracing
exception handlers with name binding. Patch by Pablo Galindo.
4 changes: 3 additions & 1 deletion Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -3610,7 +3610,9 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
PUSH(val);
PUSH(exc);
JUMPTO(handler);
if (_Py_TracingPossible(ceval)) {
if (_Py_TracingPossible(ceval) &&
((f->f_lasti < instr_lb || f->f_lasti >= instr_ub) ||
!(f->f_lasti == instr_lb || f->f_lasti < instr_prev))) {
/* Make sure that we trace line after exception */
instr_prev = INT_MAX;
}
Expand Down