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
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:
assignee=Noneclosed_at=Nonecreated_at=<Date2017-01-23.10:26:05.098>labels= ['3.7', 'type-feature', 'library']
title='Add support of multiple signatures'updated_at=<Date2017-01-23.17:51:01.471>user='https://github.com/serhiy-storchaka'
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:
type(obj)
type(name, bases, mapping)
do this:
type(obj_or_name, bases=None, mapping=None)
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().
#117671 is a draft implementation. It adds MultiSignature, which is a subclass of Signature, but supports iteration and has length. inspect.signatures() always returns a MultiSignature, even if it contains a single signature. inspect.signature() can also return a MultiSignature. pydoc and all other stdlib code was updated to support multisignatures. All builtin functions and methods of builtin classes except type() and super() has now signatures, i.e. are supported by inspect.signature() and inspect.signatures().
MultiSignature's attribute parameters is a union of all parameters in all subsignatures, and return_annotation is a union of return annotations of subsignatures. bind() and bind_partial() are supported, but replace() does not.
Future features:
Union and itersection of Signature and MultiSignature objects. An intersection will be useful to find the common signature for __new__ and __init__ methods (one of them can contain *args, **kwargs).
Partial signature. Like bind_partial(), but instead of a BoundArguments object it should return a new (multi-)signature object after binding arguments. It will help to get the signature of bound and class methods, partial and partialmethod objects.
Generate multi-signatures in Argument Clinic if default values are not representable.
Generate multi-signatures in Argument Clinic for optional groups.
Support multi-signatures in functools.singledispatch and typing.override().
Reacted by Erlend E. Aasland, Sergey B Kirpichev and Kirill Podoprigora
IMO, this should be a PEP.
It's an exciting improvement, and it has a wide reach -- areas like typing, dynamic dispatch, or documentation will all be affected.
Activity
serhiy-storchaka commentedon Jan 23, 2017
Some functions can be described by the single signature. See examples in msg285647. Selected examples:
I think the only way to resolve this problem is to add the support of multiple signatures in inspect, pydoc, Argument Clinic, etc.
1st1 commentedon Jan 23, 2017
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:
type(obj)
type(name, bases, mapping)
do this:
type(obj_or_name, bases=None, mapping=None)
And explain what really is going on in the docstring?
serhiy-storchaka commentedon Jan 23, 2017
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().
pythongh-73536: Add support of multi-signatures
pythongh-73536: Add support of multi-signatures
serhiy-storchaka commentedon Apr 9, 2024
#117671 is a draft implementation. It adds MultiSignature, which is a subclass of Signature, but supports iteration and has length.
inspect.signatures()always returns a MultiSignature, even if it contains a single signature.inspect.signature()can also return a MultiSignature.pydocand all other stdlib code was updated to support multisignatures. All builtin functions and methods of builtin classes excepttype()andsuper()has now signatures, i.e. are supported byinspect.signature()andinspect.signatures().MultiSignature's attribute
parametersis a union of all parameters in all subsignatures, andreturn_annotationis a union of return annotations of subsignatures.bind()andbind_partial()are supported, butreplace()does not.Future features:
__new__and__init__methods (one of them can contain*args, **kwargs).bind_partial(), but instead of a BoundArguments object it should return a new (multi-)signature object after binding arguments. It will help to get the signature of bound and class methods,partialandpartialmethodobjects.functools.singledispatchandtyping.override().encukou commentedon Apr 10, 2024
IMO, this should be a PEP.
It's an exciting improvement, and it has a wide reach -- areas like typing, dynamic dispatch, or documentation will all be affected.
skirpichev commentedon Apr 4, 2025
[-]Add support of multiple signatures[/-][+]Add support for multiple signatures[/+]dict()should match the doc ofdict()and it should be more understandable #137629 as a duplicate of this issue