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

Incorrect description of the __signature__ attribute in docs #115937

Closed
Labels
docsDocumentation in the Doc dirtype-bugAn unexpected behavior, bug, or error
@skirpichev

Description

@skirpichev

Bug report

Bug description:

Since#106311 its documented in theinspect.signature() sphinx docs as:
"If the passed object has a__signature__ attribute, this function returns it without further computations."

That looks correct per PEP 362, see theimplementation section. But actual code logic goes far away from this simple description:

cpython/Lib/inspect.py

Lines 2549 to 2562 in8e8ab75

ifsigisnotNone:
# since __text_signature__ is not writable on classes, __signature__
# may contain text (or be a callable that returns text);
# if so, convert it
o_sig=sig
ifnotisinstance(sig, (Signature,str))andcallable(sig):
sig=sig()
ifisinstance(sig,str):
sig=_signature_fromstr(sigcls,obj,sig)
ifnotisinstance(sig,Signature):
raiseTypeError(
'unexpected object {!r} in __signature__ '
'attribute'.format(o_sig))
returnsig

Either we should document this properly (then this is a documentation issue). Or we could change the code and remove undocumented logic. As this attribute was documented recently, I'll suggest the second option.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dirtype-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