[Python-ideas] singledispatch for instance methods
Juancarlo Añez
apalala at gmail.com
Sun May 14 13:57:47 EDT 2017
On Sun, May 14, 2017 at 1:28 PM, Steven D’Aprano <steve at pearwood.info>
wrote:
- contact Tim Mitchell and see if his offer of contributing the code
> still stands;
>
FWIW, this is a Python implementation of a single-dispatch decorator for
methods that I wrote from looking at the stdlib, and that I have used
successfully in some projects:
from functools import singledispatchfrom functools import update_wrapper
def singledispatch_method(method):
dispatcher = singledispatch(method)
def wrapper(*args, **kw):
return dispatcher.dispatch(args[1].__class__)(*args, **kw)
wrapper.register = dispatcher.register
update_wrapper(wrapper, method)
return wrapper
--
Juancarlo *Añez*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170514/89e2b1e7/attachment.html>
More information about the Python-ideas
mailing list