Bug report
Bug description:
Since #106311 its documented in the inspect.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 the implementation section. But actual code logic goes far away from this simple description:
|
if sig is not None: |
|
# 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 |
|
if not isinstance(sig, (Signature, str)) and callable(sig): |
|
sig = sig() |
|
if isinstance(sig, str): |
|
sig = _signature_fromstr(sigcls, obj, sig) |
|
if not isinstance(sig, Signature): |
|
raise TypeError( |
|
'unexpected object {!r} in __signature__ ' |
|
'attribute'.format(o_sig)) |
|
return sig |
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
Bug report
Bug description:
Since #106311 its documented in the
inspect.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 the implementation section. But actual code logic goes far away from this simple description:
cpython/Lib/inspect.py
Lines 2549 to 2562 in 8e8ab75
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