Skip to content

Regression in inspect.getsourcelines from 3.13.7 to 3.13.8Β #139923

@itamaro

Description

@itamaro

Bug report

Bug description:

It seems that 3.13.8 introduced a breaking change in how inspect.getsourcelines handles comments between a decorator and the function being decorated

Minimal reproducer:

import inspect

def decorate(func):
    return func

@decorate
# harmless comment
def spam() -> None:
    pass

print(inspect.getsourcelines(spam))

output with 3.13.7:

(['@decorate\n', 'def spam() -> None:\n', '    pass\n'], 7)

output with 3.13.8 (the pass line is missing):

(['@decorate\n', '# harmless comment\n', 'def spam() -> None:\n'], 6)

there's also a difference in the line number for some reason

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard 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