summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2021-11-19 15:16:49 (GMT)
committerGitHub <noreply@github.com>2021-11-19 15:16:49 (GMT)
commit337cb480e9dc1d27594ebd87a0045d00ec8b1c3a (patch)
tree6cf0a9ea5560ef9ab89287f2a61cdeb8589cd987
parent29e5874d5a9205c488f783356d0cf3f115399327 (diff)
downloadcpython-337cb480e9dc1d27594ebd87a0045d00ec8b1c3a.zip
cpython-337cb480e9dc1d27594ebd87a0045d00ec8b1c3a.tar.gz
cpython-337cb480e9dc1d27594ebd87a0045d00ec8b1c3a.tar.bz2
bpo-45709: Fix tracing when exception is handled. (GH-29638)
-rw-r--r--Lib/test/test_sys_settrace.py32
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2021-11-19-13-17-47.bpo-45709.H_t7ut.rst2
-rw-r--r--Python/ceval.c5
3 files changed, 35 insertions, 4 deletions
diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py
index 3fe0bb7..b565bef 100644
--- a/Lib/test/test_sys_settrace.py
+++ b/Lib/test/test_sys_settrace.py
@@ -1137,6 +1137,38 @@ class TraceTestCase(unittest.TestCase):
(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"""
diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-11-19-13-17-47.bpo-45709.H_t7ut.rst b/Misc/NEWS.d/next/Core and Builtins/2021-11-19-13-17-47.bpo-45709.H_t7ut.rst
new file mode 100644
index 0000000..e3b0070
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2021-11-19-13-17-47.bpo-45709.H_t7ut.rst
@@ -0,0 +1,2 @@
+Restore behavior from 3.10 when tracing an exception raised within a with
+statement.
diff --git a/Python/ceval.c b/Python/ceval.c
index 9d3ff74..9e56b50 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -5093,10 +5093,7 @@ exception_unwind:
JUMPTO(handler);
/* Resume normal execution */
frame->f_state = FRAME_EXECUTING;
- frame->f_lasti = handler;
- NEXTOPARG();
- PRE_DISPATCH_GOTO();
- DISPATCH_GOTO();
+ DISPATCH();
}
exiting: