diff --git a/pyext.py b/pyext.py index 2f4645a..221b2dc 100644 --- a/pyext.py +++ b/pyext.py @@ -31,6 +31,9 @@ import sys, inspect, types, functools +if not hasattr(inspect, 'getargspec'): + inspect.getargspec = inspect.getfullargspec + def _targspec(func, specs, attr='__orig_arg__'): if hasattr(func, '__is_overload__') and func.__is_overload__: return getattr(func, attr) @@ -127,11 +130,26 @@ def _argspec(func): except ImportError: IPython = None else: - # Replace IPython's argspec - oipyargspec = IPython.core.oinspect.getargspec + try: + oipyargspec = IPython.core.oinspect.getargspec + except AttributeError: + + def _get_ipython_argspec(func): + if hasattr(inspect, "getfullargspec"): + argspec = inspect.getfullargspec(func) + else: + argspec = inspect.getargspec(func) + return argspec + + oipyargspec = _get_ipython_argspec + def _ipyargspec(func): return _targspec(func, oipyargspec, '__orig_arg_ipy__') - IPython.core.oinspect.getargspec = _ipyargspec + + try: + IPython.core.oinspect.getargspec = _ipyargspec + except AttributeError: + pass class overload(object): '''Simple function overloading in Python.'''