[Python-ideas] singledispatch for methods

Tim Mitchell tim.mitchell.chch at gmail.com
Wed Mar 27 04:28:21 EDT 2019


The motivation is the same as for functools.singledispatch (
https://www.python.org/dev/peps/pep-0443/) - provide generic methods. These
are useful for visitor implementations that are cleaner than the
visit_<class_name> approach typically used today (e.g.
https://github.com/mbr/visitor).  It is also useful for writing serialisers
and encoders.
The motivation is also that people keep using the method name munging
approach (e.g. mypy) because functools.singledispatch only works on
functions and not class methods.

Cheers
Tim

On Wed, Mar 27, 2019 at 4:33 PM Michael Selik <michael.selik at gmail.com>
wrote:

> On Tue, Mar 26, 2019, 1:09 PM Tim Mitchell <tim.mitchell.chch at gmail.com>
> wrote:
>
>> Is it time to add singledispatch for methods to the core library?
>>
>
> What's the motivation for it, beyond the fact that it's possible?
>
> Regarding jargon, aren't Python's instance methods are already
> single-dispatch, because they receive the instance as the first argument?
>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190327/daba8b6d/attachment.html>


More information about the Python-ideas mailing list