[Python-Dev] PEP 443 - Single-dispatch generic functions

Ronan Lamy ronan.lamy at gmail.com
Thu May 23 23:02:46 CEST 2013

2013/5/23 Łukasz Langa <lukasz at langa.pl>

> On 23 maj 2013, at 20:13, Éric Araujo <merwok at netwok.org> wrote:
> > Question: what happens if two functions (say in two different modules)
> > are registered for the same type?
> Last one wins. Just like with assigning names in a scope, defining methods
> in a class or overriding them in a subclass.

This is a serious annoyance, considering that there are several places
where a large library can reasonably define the implementations (i.e. with
the class, with the function, or in some utility module). Note that in
contrast with the case of functions in a module or methods in a class,
linting tools cannot be expected to detect a duplication between functions
with different names defined in different modules.

Another thing missing from the PEP is the ability to access the
implementation function when you know the generic function and the class. A
major use case for this is to define the implementation for a subclass by
reusing its parent's implementation, e.g. :

def _(arg):
    print("Hello from my_int!")
    return some_generic[int](arg)

Ronan Lamy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20130523/eb4d848d/attachment.html>

More information about the Python-Dev mailing list