Closed
Description
def f():
[(x,
2*x)
for x
in [1,2,3] if (x > 0
and x < 100
and x != 50)]
f = f.__code__.co_consts[1]
import dis
from pprint import pprint as pp
def pos(p):
return (p.lineno, p.end_lineno, p.col_offset, p.end_col_offset)
pp([(pos(x.positions), x.opname, x.argval) for x in dis.get_instructions(f)])
The output is:
[((3, 3, 0, 0), 'RESUME', 0),
((3, 8, 2, 31), 'BUILD_LIST', 0),
((3, 8, 2, 31), 'LOAD_FAST', '.0'),
((3, 8, 2, 31), 'FOR_ITER', 66),
((5, 5, 7, 8), 'STORE_FAST', 'x'),
((6, 6, 18, 19), 'LOAD_FAST', 'x'),
((6, 6, 22, 23), 'LOAD_CONST', 0),
((6, 6, 18, 23), 'COMPARE_OP', '>'),
((6, 6, 18, 23), 'POP_JUMP_IF_FALSE', 64),
((7, 7, 22, 23), 'LOAD_FAST', 'x'),
((7, 7, 26, 29), 'LOAD_CONST', 100),
((7, 7, 22, 29), 'COMPARE_OP', '<'),
((7, 7, 22, 29), 'POP_JUMP_IF_FALSE', 64),
((8, 8, 22, 23), 'LOAD_FAST', 'x'),
((8, 8, 27, 29), 'LOAD_CONST', 50),
((8, 8, 22, 29), 'COMPARE_OP', '!='),
((8, 8, 22, 29), 'POP_JUMP_IF_TRUE', 50),
((None, None, None, None), 'JUMP_BACKWARD', 6),
((3, 3, 4, 5), 'LOAD_FAST', 'x'),
((4, 4, 3, 4), 'LOAD_CONST', 2),
((4, 4, 5, 6), 'LOAD_FAST', 'x'),
((4, 4, 3, 6), 'BINARY_OP', 5),
((3, 4, 3, 7), 'BUILD_TUPLE', 2),
((8, 8, 22, 29), 'LIST_APPEND', 2), <-- incorrect from here to the end
((8, 8, 22, 29), 'JUMP_BACKWARD', 6),
((8, 8, 22, 29), 'RETURN_VALUE', None)]