MCPcopy Index your code
hub / github.com/python/cpython / check_jump_targets

Method check_jump_targets

Lib/test/test_peepholer.py:54–69  ·  view source on GitHub ↗
(self, code)

Source from the content-addressed store, hash-verified

52class TestTranforms(BytecodeTestCase):
53
54 def check_jump_targets(self, code):
55 instructions = list(dis.get_instructions(code))
56 targets = {instr.offset: instr for instr in instructions}
57 for instr in instructions:
58 if 'JUMP_' not in instr.opname:
59 continue
60 tgt = targets[instr.argval]
61 # jump to unconditional jump
62 if tgt.opname in ('JUMP_BACKWARD', 'JUMP_FORWARD'):
63 self.fail(f'{instr.opname} at {instr.offset} '
64 f'jumps to {tgt.opname} at {tgt.offset}')
65 # unconditional jump to RETURN_VALUE
66 if (instr.opname in ('JUMP_BACKWARD', 'JUMP_FORWARD') and
67 tgt.opname == 'RETURN_VALUE'):
68 self.fail(f'{instr.opname} at {instr.offset} '
69 f'jumps to {tgt.opname} at {tgt.offset}')
70
71 def check_lnotab(self, code):
72 "Check that the lnotab byte offsets are sensible."

Calls 3

listClass · 0.85
get_instructionsMethod · 0.80
failMethod · 0.45

Tested by

no test coverage detected