Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

3.13 Regression:inspect.getsource() returns incorrect source code #122981

Closed
Labels
3.13bugs and security fixes3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@mhils

Description

@mhils

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

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp