Skip to content

Commit

Permalink
Issue 488/remove mutable default args in panel (#694)
Browse files Browse the repository at this point in the history
* remove dangerous_default_arg from param_reprs

* remove dangerous default value warning from Viewable.save

* fix dangerouse default value for stages in Pipeline constructor

* fix dangerous default for kwargs _InteractFactory constructor

* fix bug with stages var in pipeline constructor

* remove dangerous default for widget_types in HoloViews.widgets_from_dimensions
  • Loading branch information
xtaje authored and philippjfr committed Oct 12, 2019
1 parent e8ad7e6 commit 559c09a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions panel/interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,10 @@ class _InteractFactory(object):
kwargs: dict
A dict of **kwargs to use for widgets.
"""
def __init__(self, cls, options, kwargs={}):
def __init__(self, cls, options, kwargs=None):
self.cls = cls
self.opts = options
self.kwargs = kwargs
self.kwargs = kwargs or {}

def widget(self, f):
"""
Expand Down
5 changes: 4 additions & 1 deletion panel/pane/holoviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def applies(cls, obj):
return isinstance(obj, Dimensioned) or isinstance(obj, Plot)

@classmethod
def widgets_from_dimensions(cls, object, widget_types={}, widgets_type='individual'):
def widgets_from_dimensions(cls, object, widget_types=None, widgets_type='individual'):
from holoviews.core import Dimension, DynamicMap
from holoviews.core.options import SkipRendering
from holoviews.core.util import isnumeric, unicode, datetime_types, unique_iterator
Expand All @@ -289,6 +289,9 @@ def widgets_from_dimensions(cls, object, widget_types={}, widgets_type='individu
from holoviews.plotting.util import get_dynamic_mode
from ..widgets import Widget, DiscreteSlider, Select, FloatSlider, DatetimeInput, IntSlider

if widget_types is None:
widget_types = {}

if isinstance(object, GenericCompositePlot):
object = object.layout
elif isinstance(object, Plot):
Expand Down
6 changes: 3 additions & 3 deletions panel/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ class Pipeline(param.Parameterized):

previous = param.Action(default=lambda x: x.param.trigger('previous'))

def __init__(self, stages=[], **params):
def __init__(self, stages=None, **params):
try:
import holoviews as hv
except:
raise ImportError('Pipeline requires holoviews to be installed')

self._stages = list(stages)
self._stages = [] if stages is None else list(stages)
self._stage = 0
super(Pipeline, self).__init__(**params)
self._error = Markdown('')
Expand All @@ -50,7 +50,7 @@ def __init__(self, stages=[], **params):
spinner = Pane(os.path.join(os.path.dirname(__file__), 'assets', 'spinner.gif'))
self._spinner_layout = Row(HSpacer(), Column(VSpacer(), spinner, VSpacer()), HSpacer())
stage_layout = Row()
if len(stages):
if stages:
stage_layout.append(self._init_stage())
self._layout = Column(self._progress_bar, self._error, stage_layout)

Expand Down
4 changes: 2 additions & 2 deletions panel/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def abbreviated_repr(value, max_length=25, natural_breaks=(',', ' ')):
return vrepr


def param_reprs(parameterized, skip=[]):
def param_reprs(parameterized, skip=None):
"""
Returns a list of reprs for parameters on the parameterized object.
Skips default and empty values.
Expand All @@ -131,7 +131,7 @@ def param_reprs(parameterized, skip=[]):
elif isinstance(v, string_types) and v == '': continue
elif isinstance(v, list) and v == []: continue
elif isinstance(v, dict) and v == {}: continue
elif p in skip or (p == 'name' and v.startswith(cls)): continue
elif (skip and p in skip) or (p == 'name' and v.startswith(cls)): continue
param_reprs.append('%s=%s' % (p, abbreviated_repr(v)))
return param_reprs

Expand Down
6 changes: 5 additions & 1 deletion panel/viewable.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def get_root(self, doc=None, comm=None):
return root

def save(self, filename, title=None, resources=None, template=None,
template_variables={}, embed=False, max_states=1000,
template_variables=None, embed=False, max_states=1000,
max_opts=3, embed_json=False, json_prefix='', save_path='./',
load_path=None):
"""
Expand All @@ -436,6 +436,10 @@ def save(self, filename, title=None, resources=None, template=None,
Optional title for the plot
resources: bokeh resources
One of the valid bokeh.resources (e.g. CDN or INLINE)
template:
passed to underlying io.save
template_variables:
passed to underlying io.save
embed: bool
Whether the state space should be embedded in the saved file.
max_states: int
Expand Down

0 comments on commit 559c09a

Please sign in to comment.