Skip to content

inspect.getsourcelines broken on commented decorators in 3.13.8 #140268

Closed as duplicate

Description

@dmadisetti

Bug report

Bug description:

Off by one error in extracting the source with inspect.getsourcelines When there is a more than one line break between the decorator and the function definition.

import inspect

decorator = lambda fn: fn

@decorator
# Hello World
def decorated(a, b):
    return a + b

code, _lnum = inspect.getsourcelines(decorated)
print("".join(code))

Running with 3.13.7 gives

@decorator
# Hello World
def decorated(a, b):
    return a + b

Running with 3.13.8 gives:

@decorator
# Hello World
def decorated(a, b):

Doesn't have to be a comment

@decorator

def decorated(a, b):
    ...

produces the behavior and multiple line breaks still give the same off by one error.

CPython versions tested on:

3.13

Operating systems tested on:

macOS

Activity

  1. dmadisetti commented on Oct 17, 2025

    @dmadisetti
    Author

    Ahh, likely a dupe of #139838

  2. itamaro commented on Oct 18, 2025

    @itamaro
    Contributor

    Ahh, likely a dupe of #139838

    looks more like a dup of gh-139783, which has been fixed in 3.13.9

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions