diff options
author | Mark Shannon <mark@hotpy.org> | 2021-01-13 12:05:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-13 12:05:43 (GMT) |
commit | 3bd6035b6baf1a7d51b7cc2c6bb2c81886236b67 (patch) | |
tree | 22746e3a5738e389725765ade3167911eba51b9a /Lib/test | |
parent | 2396614b8958ad202378fd71a598eb4106ac5896 (diff) | |
download | cpython-3bd6035b6baf1a7d51b7cc2c6bb2c81886236b67.zip cpython-3bd6035b6baf1a7d51b7cc2c6bb2c81886236b67.tar.gz cpython-3bd6035b6baf1a7d51b7cc2c6bb2c81886236b67.tar.bz2 |
bpo-42908: Mark cleanup code at end of try-except and with artificial (#24202)
* Mark bytecodes at end of try-except as artificial.
* Make sure that the CFG is consistent throughout optimiization.
* Extend line-number propagation logic so that implicit returns after 'try-except' or 'with' have the correct line numbers.
* Update importlib
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_dis.py | 2 | ||||
-rw-r--r-- | Lib/test/test_sys_settrace.py | 40 |
2 files changed, 41 insertions, 1 deletions
diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py index 0383124..e342a14 100644 --- a/Lib/test/test_dis.py +++ b/Lib/test/test_dis.py @@ -1026,7 +1026,7 @@ expected_opinfo_jumpy = [ Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=42, argval=42, argrepr='', offset=36, starts_line=None, is_jump_target=False), Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=38, starts_line=8, is_jump_target=False), Instruction(opname='JUMP_ABSOLUTE', opcode=113, arg=52, argval=52, argrepr='', offset=40, starts_line=None, is_jump_target=False), - Instruction(opname='JUMP_ABSOLUTE', opcode=113, arg=8, argval=8, argrepr='', offset=42, starts_line=None, is_jump_target=True), + Instruction(opname='JUMP_ABSOLUTE', opcode=113, arg=8, argval=8, argrepr='', offset=42, starts_line=7, is_jump_target=True), Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=44, starts_line=10, is_jump_target=True), Instruction(opname='LOAD_CONST', opcode=100, arg=4, argval='I can haz else clause?', argrepr="'I can haz else clause?'", offset=46, starts_line=None, is_jump_target=False), Instruction(opname='CALL_FUNCTION', opcode=131, arg=1, argval=1, argrepr='', offset=48, starts_line=None, is_jump_target=False), diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py index 83b0392..4298986 100644 --- a/Lib/test/test_sys_settrace.py +++ b/Lib/test/test_sys_settrace.py @@ -916,6 +916,46 @@ class TraceTestCase(unittest.TestCase): (7, 'line'), (7, 'return')]) + def test_if_false_in_with(self): + + class C: + def __enter__(self): + return self + def __exit__(*args): + pass + + def func(): + with C(): + if False: + pass + + self.run_and_compare(func, + [(0, 'call'), + (1, 'line'), + (-5, 'call'), + (-4, 'line'), + (-4, 'return'), + (2, 'line'), + (-3, 'call'), + (-2, 'line'), + (-2, 'return'), + (2, 'return')]) + + def test_if_false_in_try_except(self): + + def func(): + try: + if False: + pass + except Exception: + X + + self.run_and_compare(func, + [(0, 'call'), + (1, 'line'), + (2, 'line'), + (2, 'return')]) + class SkipLineEventsTraceTestCase(TraceTestCase): """Repeat the trace tests, but with per-line events skipped""" |