diff options
author | Ceridwen <ceridwenv@gmail.com> | 2015-11-16 15:38:33 -0500 |
---|---|---|
committer | Ceridwen <ceridwenv@gmail.com> | 2015-11-16 15:38:33 -0500 |
commit | 58c9a608fdb58bd5147e5c938b12c9c7a7b69040 (patch) | |
tree | 5b1793d15ac8038d327ca57e59e483cf8cd732b0 /astroid/util.py | |
parent | f4fad7a967e956bb283afb196468832f3c93d7d6 (diff) | |
download | astroid-git-58c9a608fdb58bd5147e5c938b12c9c7a7b69040.tar.gz |
Add a workaround for singledispatch raising AttributeError on old-style classes
Diffstat (limited to 'astroid/util.py')
-rw-r--r-- | astroid/util.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/astroid/util.py b/astroid/util.py index 71281748..9c20eb4b 100644 --- a/astroid/util.py +++ b/astroid/util.py @@ -26,13 +26,27 @@ import warnings import lazy_object_proxy import six +import wrapt JYTHON = True if platform.python_implementation() == 'Jython' else False try: - from functools import singledispatch as singledispatch + from functools import singledispatch as _singledispatch except ImportError: - from singledispatch import singledispatch as singledispatch + from singledispatch import singledispatch as _singledispatch + + +def singledispatch(func): + old_generic_func = _singledispatch(func) + @wrapt.decorator + def wrapper(func, instance, args, kws): + return old_generic_func.dispatch(type(args[0]))(*args, **kws) + new_generic_func = wrapper(func) + new_generic_func.register = old_generic_func.register + new_generic_func.dispatch = old_generic_func.dispatch + new_generic_func.registry = old_generic_func.registry + new_generic_func._clear_cache = old_generic_func._clear_cache + return new_generic_func def lazy_import(module_name): |