[Python-checkins] bpo-45709: Fix tracing when exception is handled. (GH-29638)
markshannon
webhook-mailer at python.org
Fri Nov 19 10:16:59 EST 2021
https://github.com/python/cpython/commit/337cb480e9dc1d27594ebd87a0045d00ec8b1c3a
commit: 337cb480e9dc1d27594ebd87a0045d00ec8b1c3a
branch: main
author: Mark Shannon <mark at hotpy.org>
committer: markshannon <mark at hotpy.org>
date: 2021-11-19T15:16:49Z
summary:
bpo-45709: Fix tracing when exception is handled. (GH-29638)
files:
A Misc/NEWS.d/next/Core and Builtins/2021-11-19-13-17-47.bpo-45709.H_t7ut.rst
M Lib/test/test_sys_settrace.py
M Python/ceval.c
diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py
index 3fe0bb7f460b9..b565bef4c4423 100644
--- a/Lib/test/test_sys_settrace.py
+++ b/Lib/test/test_sys_settrace.py
@@ -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"""
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 0000000000000..e3b007048cd6c
--- /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 9d3ff74bace6c..9e56b50ee844b 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -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:
More information about the Python-checkins
mailing list