diff options
author | Mark Shannon <mark@hotpy.org> | 2021-06-03 15:45:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-03 15:45:58 (GMT) |
commit | 937cebc93b4922583218e0cbf0a9a14705a595b2 (patch) | |
tree | c1d1850a46f708810ab72827e8fe82b5e2921317 /Lib | |
parent | 4eed2821d40373345ed133b2b8d912fef59acab7 (diff) | |
download | cpython-937cebc93b4922583218e0cbf0a9a14705a595b2.zip cpython-937cebc93b4922583218e0cbf0a9a14705a595b2.tar.gz cpython-937cebc93b4922583218e0cbf0a9a14705a595b2.tar.bz2 |
bpo-44298: Fix line numbers for early exits in with statements. (GH-26513)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_sys_settrace.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py index 5787269..5f2b908 100644 --- a/Lib/test/test_sys_settrace.py +++ b/Lib/test/test_sys_settrace.py @@ -995,6 +995,52 @@ class TraceTestCase(unittest.TestCase): (5, 'line'), (5, 'return')]) + def test_early_exit_with(self): + + class C: + def __enter__(self): + return self + def __exit__(*args): + pass + + def func_break(): + for i in (1,2): + with C(): + break + pass + + def func_return(): + with C(): + return + + self.run_and_compare(func_break, + [(0, 'call'), + (1, 'line'), + (2, 'line'), + (-5, 'call'), + (-4, 'line'), + (-4, 'return'), + (3, 'line'), + (2, 'line'), + (-3, 'call'), + (-2, 'line'), + (-2, 'return'), + (4, 'line'), + (4, 'return')]) + + self.run_and_compare(func_return, + [(0, 'call'), + (1, 'line'), + (-11, 'call'), + (-10, 'line'), + (-10, 'return'), + (2, 'line'), + (1, 'line'), + (-9, 'call'), + (-8, 'line'), + (-8, 'return'), + (1, 'return')]) + class SkipLineEventsTraceTestCase(TraceTestCase): """Repeat the trace tests, but with per-line events skipped""" |