Skip to content

Commit

Permalink
bpo-45709: Fix tracing when exception is handled. (GH-29638)
Browse files Browse the repository at this point in the history
  • Loading branch information
markshannon committed Nov 19, 2021
1 parent 29e5874 commit 337cb48
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
32 changes: 32 additions & 0 deletions Lib/test/test_sys_settrace.py
Expand Up @@ -1137,6 +1137,38 @@ def func():
(7, 'line'),
(7, 'return')])

def test_tracing_exception_raised_in_with(self):

class NullCtx:
def __enter__(self):
return self
def __exit__(self, *excinfo):
pass

def func():
try:
with NullCtx():
1/0
except ZeroDivisionError:
pass

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


class SkipLineEventsTraceTestCase(TraceTestCase):
"""Repeat the trace tests, but with per-line events skipped"""
Expand Down
@@ -0,0 +1,2 @@
Restore behavior from 3.10 when tracing an exception raised within a with
statement.
5 changes: 1 addition & 4 deletions Python/ceval.c
Expand Up @@ -5093,10 +5093,7 @@ MISS_WITH_OPARG_COUNTER(STORE_SUBSCR)
JUMPTO(handler);
/* Resume normal execution */
frame->f_state = FRAME_EXECUTING;
frame->f_lasti = handler;
NEXTOPARG();
PRE_DISPATCH_GOTO();
DISPATCH_GOTO();
DISPATCH();
}

exiting:
Expand Down

0 comments on commit 337cb48

Please sign in to comment.