On 8/23/21 10:21 PM, Steven D'Aprano wrote:

> On Mon, Aug 23, 2021 at 09:10:49PM -0500, Will Bradley wrote:
>> Don't know if this is already a PEP, but I'd love to see something like this
>> <https://www.codementor.io/@arpitbhayani/overload-functions-in-python-13e32ahzqt>
>> in
>> Python— a decorator @overload that creates multiple copies of
>> functions/methods based on their arguments' types. (This is much narrower
>> in scope than PEP 3124, before anyone asks.)
> Do you mean something like functools.singledispatch?
>
> https://docs.python.org/3/library/functools.html#functools.singledispatch
>
> If not, how are they different?
>
You may also be interested in a package I wrote for doing this kind of thing:

https://pypi.org/project/signature-dispatch/

The differences between `functools.singledispatch`, the linked article, and my
package are:

* `functools.singledispatch` considers only the type of the first argument.

* The linked article only considers the number of positional arguments.

* My package considers the entire signature, including type annotations.

-Kale

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/33BH42IOYTTXX5G3EDCYQPTTYDET7JNM/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to