The Wayback Machine - https://web.archive.org/web/20250610084953/https://github.com/python/cpython/issues/114671
Skip to content

3.13: not a == b has incorrect bytecode positions #114671

Closed as not planned
Closed as not planned
@15r10nk

Description

@15r10nk

Bug report

Bug description:

The following code reproduces the bug:

import dis

code = """
not a == b 
"""

code = compile(code, "<code>", "exec")

for bc in dis.get_instructions(code):
    p = bc.positions
    print(
        f"{p.lineno}:{p.col_offset} {p.end_lineno}:{p.end_col_offset}",
        bc.opname,
        bc.argval,
    )


for bc in dis.get_instructions(code):
    if bc.opname == "COMPARE_OP":
        assert bc.positions.col_offset == 4

output (Python 3.13.0a3+):

0:0 1:0 RESUME 0
2:4 2:5 LOAD_NAME a
2:9 2:10 LOAD_NAME b
2:0 2:10 COMPARE_OP ==  # <-- incorrect col_offset
2:0 2:10 UNARY_NOT None
2:0 2:10 POP_TOP None
2:0 2:10 RETURN_CONST None
Traceback (most recent call last):
  File "/home/frank/projects/executing/codi.py", line 20, in <module>
    assert bc.positions.col_offset == 4
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError

The source range for the compare operation should not include the not.
There was no problem in 3.12, where the col_offset started at 4

output (Python 3.12.1):

0:0 1:0 RESUME 0
2:4 2:5 LOAD_NAME a
2:9 2:10 LOAD_NAME b
2:4 2:10 COMPARE_OP ==  # <-- correct col_offset
2:0 2:10 UNARY_NOT None
2:0 2:10 POP_TOP None
2:0 2:10 RETURN_CONST None

I bisected the problem down to 7b2d94d (@brandtbucher).
The problem can also be reproduced on the current main (7a47054).

CPython versions tested on:

3.13, CPython main branch

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixestype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions