Skip to content

Commit

Permalink
Preserving positional and keyword argument structure
Browse files Browse the repository at this point in the history
  • Loading branch information
jlstevens committed Dec 7, 2018
1 parent a6f67e8 commit 92847a0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
7 changes: 4 additions & 3 deletions holoviews/core/dimension.py
Expand Up @@ -1352,7 +1352,7 @@ def opts(self, *args, **kwargs):
Returns:
Returns the object or a clone with the options applied
"""
apply_groups, options = util.deprecated_opts_signature(args, kwargs)
apply_groups, options, new_kwargs = util.deprecated_opts_signature(args, kwargs)

# By default do not clone in .opts method
clone = kwargs.get('clone', None)
Expand All @@ -1365,8 +1365,9 @@ def opts(self, *args, **kwargs):
param.main.warning(msg)
if apply_groups:
from ..util import opts
kwargs['options'] = options
return opts.apply_groups(self, **kwargs)
if options is not None:
kwargs['options'] = options
return opts.apply_groups(self, **dict(kwargs, **new_kwargs))

kwargs['clone'] = False if clone is None else clone
return self.options(*args, **kwargs)
Expand Down
6 changes: 3 additions & 3 deletions holoviews/core/spaces.py
Expand Up @@ -137,8 +137,8 @@ def opts(self, *args, **kwargs):
Returns the object or a clone with the options applied
"""
clone = kwargs.pop('clone', None)
apply_groups, options = util.deprecated_opts_signature(args, kwargs)
data = OrderedDict([(k, v.opts(*args, **dict(kwargs, options=options)))
apply_groups, _, _ = util.deprecated_opts_signature(args, kwargs)
data = OrderedDict([(k, v.opts(*args, **kwargs))
for k, v in self.data.items()])

# By default do not clone in .opts method
Expand Down Expand Up @@ -1172,7 +1172,7 @@ def opts(self, *args, **kwargs):
from ..util import Dynamic

clone = kwargs.get('clone', None)
apply_groups, options = util.deprecated_opts_signature(args, kwargs)
apply_groups, _, _ = util.deprecated_opts_signature(args, kwargs)
# By default do not clone in .opts method
clone = (apply_groups if clone is None else clone)

Expand Down
15 changes: 9 additions & 6 deletions holoviews/core/util.py
Expand Up @@ -231,22 +231,25 @@ def deprecated_opts_signature(args, kwargs):
Returns whether opts.apply_groups should be used (as a bool) and the
corresponding options.
"""
signature = ['plot','style', 'norm', 'clone', 'backend']
groups = ['plot','style', 'norm']
signature = groups + ['clone', 'backend']
apply_groups = False
options = None
new_kwargs = {}
if len(args) > 0 and isinstance(args[0], dict):
apply_groups = True
options = args[0]
if set(args[0].keys()) <= set(groups):
new_kwargs = args[0]
else:
options = args[0]
elif kwargs and set(kwargs.keys()).issubset(set(signature)):
apply_groups = True
options = None
elif kwargs.get('options', None) is not None:
apply_groups = True
options = kwargs.pop('options')
elif not args and not kwargs:
apply_groups = True
options = None
return apply_groups, options

return apply_groups, options, new_kwargs


class periodic(Thread):
Expand Down

0 comments on commit 92847a0

Please sign in to comment.