[Python-Dev] PEP 443 - Single-dispatch generic functions
merwok at netwok.org
Thu May 23 23:17:47 CEST 2013
Le 23/05/2013 16:10, Łukasz Langa a écrit :
>> Does this work if the implementation function is called like the first
>> decorated function?
> No, the ``register()`` attribute returns the undecorated function which
> enables decorator stacking, as well as creating unit tests for each
> variant independently.
Perfect. My web framework of choice uses decorators that register
things and return the function as is and I love it. I guess the common
pattern will be to use variants of the generic function name, e.g. func
is implemented by func_int, func_str and co, which also helps debugging.
>> Making generic functions work with ABCs sounds like a requirement to me
> Yes, I will implement that.
>> 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.
Works for me.
More information about the Python-Dev