-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3.13 Regression: inspect.getsource()
returns incorrect source code
#122981
Comments
Bisected to 153b3f7, introduced by #118475. It happens because class So ISTM the issue is that the construction of |
…ython base classes Look up __firstlineno__ only in the class' dict, without searching in base classes.
Thank you for your report @mhils. I agree with @devdanzin analysis. #123001 should fix this. |
…ython base classes Look up __firstlineno__ only in the class' dict, without searching in base classes.
Awesome - thank you two for getting to the bottom of this with lightning speed! ⚡🍰 😃 |
…base classes (GH-123001) Look up __firstlineno__ only in the class' dict, without searching in base classes.
…ython base classes (pythonGH-123001) Look up __firstlineno__ only in the class' dict, without searching in base classes. (cherry picked from commit f88c14d) Co-authored-by: Serhiy Storchaka <[email protected]>
…ython base classes (pythonGH-123001) Look up __firstlineno__ only in the class' dict, without searching in base classes.
…Python base classes (GH-123001) (#123182) gh-122981: Fix inspect.getsource() for generated classes with Python base classes (GH-123001) Look up __firstlineno__ only in the class' dict, without searching in base classes. (cherry picked from commit f88c14d) Co-authored-by: Serhiy Storchaka <[email protected]>
Thank you two again! I can confirm that the issue is fixed now for $ docker run --rm python:3.13.0rc2 bash -c \
'pip install pluggy==1.5.0; python -c "import inspect, pluggy; print(inspect.getsource(pluggy.PluggyTeardownRaisedWarning))"'
[...]
"PluginManager", docker run --rm python:3.12 bash -c \
'pip install pluggy==1.5.0; python -c "import inspect, pluggy; print(inspect.getsource(pluggy.PluggyTeardownRaisedWarning))"'
[...]
OSError: could not find class definition (https://github.com/mitmproxy/pdoc/actions/runs/10772390037/job/29935976461?pr=730) Would you like me to file a new issue, or do we keep it here? Thanks! 😃 |
|
Bug report
Bug description:
In Python 3.13rc1,
inspect.getsource()
sometimes returns a "random" line for some objects.For example, here's
ssl.AlertDescription
:This line is likely https://github.com/python/cpython/blob/v3.13.0rc1/Lib/ssl.py#L1334.
In contrast, on 3.12 and below, this raises an OSError (not ideal but also not wrong):
I'm not sure why this is happening, but it also affects pytest.PytestAssertRewriteWarning and pluggy.PluggyTeardownRaisedWarning, which both extend custom classes that override
__module__
.CPython versions tested on:
3.8, 3.9, 3.10, 3.11, 3.12, 3.13
Operating systems tested on:
Linux
Linked PRs
The text was updated successfully, but these errors were encountered: