inspect.getsource returns irrelevant text when used in repl on a class defined in place
Open
Nobody has claimed this yet.
3.13
3.14
topic-repl
type-bug
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
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
- gh-126032
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue in an interactive CPython 3.13 session with inspect.getsource(B) after defining class B in place. Compare the returned text with the class definition; done means the class source is returned instead of unrelated REPL internals.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100