diff --git a/holoviews/core/util.py b/holoviews/core/util.py index 89089fa6e2..8d42eb84b1 100644 --- a/holoviews/core/util.py +++ b/holoviews/core/util.py @@ -28,6 +28,15 @@ except: import builtins as builtins # noqa (compatibility) +try: + # Python 3 + _getargspec = inspect.getfullargspec + get_keywords = lambda spec: spec.varkw +except AttributeError: + # Python 2 + _getargspec = inspect.getargspec + get_keywords = lambda spec: spec.keywords + datetime_types = (np.datetime64, dt.datetime, dt.date) timedelta_types = (np.timedelta64, dt.timedelta,) @@ -235,24 +244,24 @@ def argspec(callable_obj): if (isinstance(callable_obj, type) and issubclass(callable_obj, param.ParameterizedFunction)): # Parameterized function.__call__ considered function in py3 but not py2 - spec = inspect.getargspec(callable_obj.__call__) - args=spec.args[1:] + spec = _getargspec(callable_obj.__call__) + args = spec.args[1:] elif inspect.isfunction(callable_obj): # functions and staticmethods - return inspect.getargspec(callable_obj) + return _getargspec(callable_obj) elif isinstance(callable_obj, partial): # partials arglen = len(callable_obj.args) - spec = inspect.getargspec(callable_obj.func) + spec = _getargspec(callable_obj.func) args = [arg for arg in spec.args[arglen:] if arg not in callable_obj.keywords] elif inspect.ismethod(callable_obj): # instance and class methods - spec = inspect.getargspec(callable_obj) + spec = _getargspec(callable_obj) args = spec.args[1:] else: # callable objects return argspec(callable_obj.__call__) - return inspect.ArgSpec(args = args, - varargs = spec.varargs, - keywords = spec.keywords, - defaults = spec.defaults) + return inspect.ArgSpec(args=args, + varargs=spec.varargs, + keywords=get_keywords(spec), + defaults=spec.defaults) @@ -284,7 +293,7 @@ def validate_dynamic_argspec(callback, kdims, streams): posargs = [arg for arg in all_posargs if arg not in stream_params] kwargs = argspec.args[-len(defaults):] - if argspec.keywords is None: + if get_keywords(argspec) is None: unassigned_streams = set(stream_params) - set(argspec.args) if unassigned_streams: unassigned = ','.join(unassigned_streams)