Skip to content

inspect.getsource returns irrelevant text when used in repl on a class defined in place  #126019

@evle-zzz

Description

@evle-zzz

Bug report

Bug description:

Run interactive cpython 3.13 with following input.

>>> import inspect
>>> class B: pass
...
>>> inspect.getsource(B)
"# Important: don't add things to this module, as they will end up in the REPL's\n"

Instead of class code we get a piece of repl internals.

CPython versions tested on:

3.13

Operating systems tested on:

Windows

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixestopic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions