Closed
Description
Bug report
Bug description:
In Python 3.11, the code object of a lambda function that returns a constant value used to have location information provided for the LOAD_CONST
bytecode:
import dis
f = lambda: ...
for pos in f.__code__.co_positions():
print(*pos)
dis.dis(f)
This outputs, in Python 3.11:
2 2 0 0
2 2 12 15
2 2 0 0
2 0 RESUME 0
2 LOAD_CONST 1 (Ellipsis)
4 RETURN_VALUE
However, since Python 3.12, where RETURN_CONST
was introduced, the same code now outputs:
2 2 0 0
2 2 0 0
2 RESUME 0
RETURN_CONST 1 (Ellipsis)
with no precise location information found in any of the bytecode produced.
Note that a regular function that returns a constant value correctly provides precise location information for RETURN_CONST
in Python 3.12+:
import dis
def f():
return ...
for pos in f.__code__.co_positions():
print(*pos)
dis.dis(f)
which outputs:
2 2 0 0
3 3 11 14
2 RESUME 0
3 RETURN_CONST 1 (Ellipsis)
CPython versions tested on:
3.11, 3.12, CPython main branch
Operating systems tested on:
Linux, Windows
Linked PRs
- gh-120722: Propogate instruction location in optimization of LOAD_CONST + RETURN_VALUE with RETURN_CONST #120723
- gh-120722: Set position on RETURN_VALUE in lambda #120724
- [3.13] gh-120722: Set position on RETURN_VALUE in lambda (GH-120724) #120738
- [3.12] gh-120722: Set position on RETURN_VALUE in lambda (GH-120724) #120739