mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-100039: enhance __signature__ to work with str and callables (GH-100168)
Callables should be either class- or static-methods. Enum now uses the classmethod version to greatly improve the help given for enums and flags.
This commit is contained in:
parent
5234e1cbea
commit
a5a7cea202
5 changed files with 73 additions and 4 deletions
|
@ -2443,10 +2443,18 @@ def _signature_from_callable(obj, *,
|
|||
pass
|
||||
else:
|
||||
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(sig))
|
||||
'attribute'.format(o_sig))
|
||||
return sig
|
||||
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue