You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pydoc uses inspect.signature() to get a function signature. inspect.signature() supports Python functions, and also extension functions defined with Argument Clinic (by parsing the __text_signature__ attribute). Unfortunately Argument Clinic is used with functions whose signature cannot be expressed in Python, e.g. getattr() or dict.pop(). It produces a human readable __text_signature__, but it can not be represented as a Signature object, so inspect.signature() fails. Pydoc display generic (...) for such functions.
Since pydoc only needs a string representation of signature, not a Signature object, I propose to use __text_signature__ if inspect.signature() fails. It needs only some trivial processing.
Before:
getattr(...)
Get a named attribute from an object.
getattr(x, 'y') is equivalent to x.y
When a default argument is given, it is returned when the attribute doesn't
exist; without it, an exception is raised in that case.
After:
getattr(object, name, default=<unrepresentable>, /)
Get a named attribute from an object.
getattr(x, 'y') is equivalent to x.y
When a default argument is given, it is returned when the attribute doesn't
exist; without it, an exception is raised in that case.
Builtin functions and methods that have non-representable signatures today
will have representable signatures yesterday, and they will become unusable
for testing this feature.
So we need to add special functions and methods to the _testcapi module
that always have non-representable signatures.
)
Builtin functions and methods that have non-representable signatures today
will have representable signatures yesterday, and they will become unusable
for testing this feature.
So we need to add special functions and methods to the _testcapi module
that always have non-representable signatures.
Pydoc uses
inspect.signature()
to get a function signature.inspect.signature()
supports Python functions, and also extension functions defined with Argument Clinic (by parsing the__text_signature__
attribute). Unfortunately Argument Clinic is used with functions whose signature cannot be expressed in Python, e.g.getattr()
ordict.pop()
. It produces a human readable__text_signature__
, but it can not be represented as aSignature
object, soinspect.signature()
fails. Pydoc display generic(...)
for such functions.Since pydoc only needs a string representation of signature, not a
Signature
object, I propose to use__text_signature__
ifinspect.signature()
fails. It needs only some trivial processing.Before:
After:
Linked PRs
The text was updated successfully, but these errors were encountered: