Last active
June 1, 2022 04:06
-
-
Save iisaka51/123ffb9899a713d9c66b477742b2be15 to your computer and use it in GitHub Desktop.
sinpledispatchmethod for old version python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try: | |
# python 3.8 or later | |
from functools import singledispatchmethod | |
except ImportError: | |
from functools import singledispatch, update_wrapper | |
def singledispatchmethod(func): | |
dispatcher = singledispatch(func) | |
def wrapper(*args, **kw): | |
return dispatcher.dispatch(args[1].__class__)(*args, **kw) | |
wrapper.register = dispatcher.register | |
update_wrapper(wrapper, func) | |
return wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment