Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source locations in 'assert' bytecode are incorrect #98398

Closed
iritkatriel opened this issue Oct 18, 2022 · 4 comments
Closed

Source locations in 'assert' bytecode are incorrect #98398

iritkatriel opened this issue Oct 18, 2022 · 4 comments
Assignees
Labels
3.12 bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@iritkatriel
Copy link
Member

iritkatriel commented Oct 18, 2022

def f():
 a,bb,ccc = 1,2,3
 assert (a > 0 and
         bb > 0 and
         ccc == 4)


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)])

Output is:

[((1, 1, 0, 0), 'RESUME', 0),
 ((2, 2, 12, 17), 'LOAD_CONST', (1, 2, 3)),
 ((2, 2, 1, 9), 'UNPACK_SEQUENCE', 3),
 ((2, 2, 1, 2), 'STORE_FAST', 'a'),
 ((2, 2, 3, 5), 'STORE_FAST', 'bb'),
 ((2, 2, 6, 9), 'STORE_FAST', 'ccc'),
 ((3, 3, 9, 10), 'LOAD_FAST', 'a'),
 ((3, 3, 13, 14), 'LOAD_CONST', 0),
 ((3, 3, 9, 14), 'COMPARE_OP', '>'),
 ((3, 3, 9, 14), 'POP_JUMP_IF_FALSE', 50),
 ((4, 4, 9, 11), 'LOAD_FAST', 'bb'),
 ((4, 4, 14, 15), 'LOAD_CONST', 0),
 ((4, 4, 9, 15), 'COMPARE_OP', '>'),
 ((4, 4, 9, 15), 'POP_JUMP_IF_FALSE', 50),
 ((5, 5, 9, 12), 'LOAD_FAST', 'ccc'),
 ((5, 5, 16, 17), 'LOAD_CONST', 4),
 ((5, 5, 9, 17), 'COMPARE_OP', '=='),
 ((5, 5, 9, 17), 'POP_JUMP_IF_TRUE', 54),
 ((5, 5, 9, 17), 'LOAD_ASSERTION_ERROR', None),    <--- incorrect
 ((5, 5, 9, 17), 'RAISE_VARARGS', 1),              <--- incorrect
 ((5, 5, 9, 17), 'LOAD_CONST', None),
 ((5, 5, 9, 17), 'RETURN_VALUE', None)]
@iritkatriel iritkatriel added type-bug An unexpected behavior, bug, or error interpreter-core (Objects, Python, Grammar, and Parser dirs) 3.12 bugs and security fixes labels Oct 18, 2022
@iritkatriel iritkatriel self-assigned this Oct 18, 2022
iritkatriel added a commit to iritkatriel/cpython that referenced this issue Oct 18, 2022
@iritkatriel
Copy link
Member Author

With the PR we get:

[((1, 1, 0, 0), 'RESUME', 0),
 ((2, 2, 12, 17), 'LOAD_CONST', (1, 2, 3)),
 ((2, 2, 1, 9), 'UNPACK_SEQUENCE', 3),
 ((2, 2, 1, 2), 'STORE_FAST', 'a'),
 ((2, 2, 3, 5), 'STORE_FAST', 'bb'),
 ((2, 2, 6, 9), 'STORE_FAST', 'ccc'),
 ((3, 3, 9, 10), 'LOAD_FAST', 'a'),
 ((3, 3, 13, 14), 'LOAD_CONST', 0),
 ((3, 3, 9, 14), 'COMPARE_OP', '>'),
 ((3, 3, 9, 14), 'POP_JUMP_IF_FALSE', 50),
 ((4, 4, 9, 11), 'LOAD_FAST', 'bb'),
 ((4, 4, 14, 15), 'LOAD_CONST', 0),
 ((4, 4, 9, 15), 'COMPARE_OP', '>'),
 ((4, 4, 9, 15), 'POP_JUMP_IF_FALSE', 50),
 ((5, 5, 9, 12), 'LOAD_FAST', 'ccc'),
 ((5, 5, 16, 17), 'LOAD_CONST', 4),
 ((5, 5, 9, 17), 'COMPARE_OP', '=='),
 ((5, 5, 9, 17), 'POP_JUMP_IF_TRUE', 54),
 ((3, 5, 1, 18), 'LOAD_ASSERTION_ERROR', None),
 ((3, 5, 1, 18), 'RAISE_VARARGS', 1),
 ((5, 5, 9, 17), 'LOAD_CONST', None),
 ((5, 5, 9, 17), 'RETURN_VALUE', None)]

@pablogsal
Copy link
Member

Is this 3.12 only?

@iritkatriel
Copy link
Member Author

Probably not. Do you want to backport stuff like this?

@iritkatriel
Copy link
Member Author

@nedbat FYI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants