On Sun, May 14, 2017 at 1:28 PM, Steven D’Aprano <st...@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*
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to