Skip to content

Commit

Permalink
Merge f5b0e87 into 3f015c0
Browse files Browse the repository at this point in the history
  • Loading branch information
basnijholt committed Mar 23, 2018
2 parents 3f015c0 + f5b0e87 commit c523aec
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions holoviews/core/util.py
Expand Up @@ -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,)

Expand Down Expand Up @@ -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)



Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c523aec

Please sign in to comment.