-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
Add support for multiple signatures #73536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Some functions can be described by the single signature. See examples in msg285647. Selected examples: dict.pop(key)
dict.pop(key, default)
type(obj)
type(name, bases, mapping)
range(stop)
range(start, stop, step=1)
min(iterable, *, key=identity)
min(iterable, *, default, key=identity)
min(*args, key=identity) I think the only way to resolve this problem is to add the support of multiple signatures in inspect, pydoc, Argument Clinic, etc. |
Signature object provides methods like .bind(), which will be hard to define if a function has many signatures. Also, inspect.signature currently returns one Signature object, that shouldn't be changed. Wouldn't it be easier instead of this: do this: And explain what really is going on in the docstring? |
It can be do, but I don't think it is worth. Making bases and mapping optional arguments does not make much sense to me. And there is no a value that can be used as a default value for the second parameter in dict.pop(). |
* Add inspect.MultiSignature which is a subclass of inspect.Signature. * Add inspect.signatures(). * inspect.signature() can now return a multi-signature. * Support multi-signatures in pydoc. * Support multi-signatures in IDLE calltips. * Support multi-signatures in dataclasses docstrings. * Allow multiple @text_signature in Argument Clinic. * Add representable signatures for all builtin functions and method of builtin classes except type() and super().
* Add inspect.MultiSignature which is a subclass of inspect.Signature. * Add inspect.signatures(). * inspect.signature() can now return a multi-signature. * Support multi-signatures in pydoc. * Support multi-signatures in IDLE calltips. * Support multi-signatures in dataclasses docstrings. * Allow multiple @text_signature in Argument Clinic. * Add representable signatures for all builtin functions and methods of builtin classes except type() and super().
#117671 is a draft implementation. It adds MultiSignature, which is a subclass of Signature, but supports iteration and has length. >>> import inspect
>>> inspect.signature(range)
<MultiSignature (stop, /)|(start, stop, step=1, /)>
>>> print(inspect.signature(range))
(stop, /)
(start, stop, step=1, /)
>>>
>>> inspect.signature(dict.pop)
<MultiSignature (self, key, /)|(self, key, default, /)>
>>> print(inspect.signature(dict.pop))
(self, key, /)
(self, key, default, /)
>>>
>>> inspect.signature(min)
<MultiSignature (iterable, /, *, key=None)|(iterable, /, *, default, key=None)|(arg1, arg2, /, *args, key=None)>
>>> print(inspect.signature(min))
(iterable, /, *, key=None)
(iterable, /, *, default, key=None)
(arg1, arg2, /, *args, key=None) MultiSignature's attribute Future features:
|
IMO, this should be a PEP. |
I'm playing with Serhiy's implementation and working on a PEP. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: