Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Bug report
Bug description:
In Python 3.13rc1,inspect.getsource() sometimes returns a "random" line for some objects.
For example, here'sssl.AlertDescription:
$ docker run --rm python:3.13-rc python -c"import inspect, ssl; print(inspect.getsource(ssl.AlertDescription))"super().shutdown(how)
This line is likelyhttps://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):
$ docker run --rm python:3.12-rc python -c"import inspect, ssl; print(inspect.getsource(ssl.AlertDescription))"Traceback (most recent call last): File"<string>", line 1,in<module> File"/usr/local/lib/python3.12/inspect.py", line 1285,in getsource lines, lnum = getsourcelines(object) ^^^^^^^^^^^^^^^^^^^^^^ File"/usr/local/lib/python3.12/inspect.py", line 1267,in getsourcelines lines, lnum = findsource(object) ^^^^^^^^^^^^^^^^^^ File"/usr/local/lib/python3.12/inspect.py", line 1112,in findsource raise OSError('could not find class definition')OSError: could not find class definition
I'm not sure why this is happening, but it also affectspytest.PytestAssertRewriteWarning andpluggy.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