Skip to content

Commit 398fe55

Browse files
committed
bpo-39114: Fix tracing of except handlers with name binding
1 parent d0c92e8 commit 398fe55

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

Lib/test/test_sys_settrace.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,30 @@ def func():
481481
[(0, 'call'),
482482
(1, 'line')])
483483

484+
def test_18_except_with_name(self):
485+
def func():
486+
try:
487+
try:
488+
raise Exception
489+
except Exception as e:
490+
raise
491+
x = "Something"
492+
y = "Something"
493+
except Exception:
494+
pass
495+
496+
self.run_and_compare(func,
497+
[(0, 'call'),
498+
(1, 'line'),
499+
(2, 'line'),
500+
(3, 'line'),
501+
(3, 'exception'),
502+
(4, 'line'),
503+
(5, 'line'),
504+
(8, 'line'),
505+
(9, 'line'),
506+
(9, 'return')])
507+
484508

485509
class SkipLineEventsTraceTestCase(TraceTestCase):
486510
"""Repeat the trace tests, but with per-line events skipped"""
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix incorrent line execution reporting in trace functions when tracing
2+
exception handlers with name binding. Patch by Pablo Galindo.

Python/ceval.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3610,7 +3610,8 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
36103610
PUSH(val);
36113611
PUSH(exc);
36123612
JUMPTO(handler);
3613-
if (_Py_TracingPossible(ceval)) {
3613+
if (_Py_TracingPossible(ceval) &&
3614+
(f->f_lasti < instr_lb || f->f_lasti >= instr_ub)) {
36143615
/* Make sure that we trace line after exception */
36153616
instr_prev = INT_MAX;
36163617
}

0 commit comments

Comments
 (0)