[Python-Dev] PEP 443 - Single-dispatch generic functions (including ABC support)
lukasz at langa.pl
Fri May 31 03:05:46 CEST 2013
On 31 maj 2013, at 01:51, Łukasz Langa <lukasz at langa.pl> wrote:
> On 31 maj 2013, at 01:47, Łukasz Langa <lukasz at langa.pl> wrote:
>> class State:
>> def __init__(self):
>> self.add.register(int, self.add_int)
> Ouch, I realized this is wrong just after I hit "Send".
> self.add is a staticmethod so this registration will overload
> on every instance. Which is obviously bad.
So, after some embarrassing head banging, here's the correct
So, it *is* possible to make instance-level and class-level
registration work with the existing @singledispatch code and a
bit of plumbing. Obviously, all that is not necessary for actual
Back to the point, though. I don't feel we should complicate the
code, tests and documentation by introducing special handling
for methods. In terms of pure type-driven single dispatch, we
have a solution that was intentionally simple from the get-go.
The next step will be predicate dispatch anyway ;))
What do you think?
IRC: ambv on #python-dev
More information about the Python-Dev