Skip to content

inspect.getsourcelines() mishandles multi-line generator expressions #137477

Description

@George-Ogden

Bug report

Bug description:

import inspect

def source_error(*args):
    frame = inspect.currentframe()
    if frame is None:
        return
    frame = frame.f_back
    if frame is None:
        return
    print(inspect.getsource(frame))

def demo():
    loops = (
        None for _ in [0] if source_error(True)
    )
    list(loops)

demo()

Expected output:

def demo():
    loops = (
        None for _ in [0] if source_error(True)
    )
    list(loops)

Actual output:

    loops = (

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

3.13bugs and security fixes3.14bugs and security fixes3.15pre-release feature fixes, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions