Thanks to visit codestin.com
Credit goes to github.com

Skip to content

No precise location provided for bytecode of lambda function returning a constant value #120722

Closed
@blhsing

Description

@blhsing

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions