Skip to content

Commit 02adc54

Browse files
committed
Allow PlotlyDict and PlotlyList to be used.
We can now instantiate them with a `_name` kwarg, which is how we’ll get around needing special classes for each object.
1 parent 1b0f007 commit 02adc54

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

plotly/graph_objs/graph_objs.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,17 @@ class PlotlyList(list, PlotlyBase):
121121
_name = None
122122

123123
def __init__(self, *args, **kwargs):
124+
_raise = kwargs.get('_raise', True)
125+
if self._name is None:
126+
self.__dict__['_name'] = kwargs.pop('_name', None)
127+
self.__dict__['_parent'] = kwargs.get('_parent')
128+
self.__dict__['_parent_key'] = kwargs.get('_parent_key')
129+
124130
if self._name is None:
125131
raise exceptions.PlotlyError(
126132
"PlotlyList is a base class. It's shouldn't be instantiated."
127133
)
128134

129-
_raise = kwargs.get('_raise', True)
130-
self.__dict__['_parent'] = kwargs.get('_parent')
131-
self.__dict__['_parent_key'] = kwargs.get('_parent_key')
132-
133135
if args and isinstance(args[0], dict):
134136
raise exceptions.PlotlyListEntryError(
135137
obj=self,
@@ -347,15 +349,18 @@ class PlotlyDict(dict, PlotlyBase):
347349
_subplot_attributes = None
348350

349351
def __init__(self, *args, **kwargs):
350-
if self._name is None:
351-
raise exceptions.PlotlyError(
352-
"PlotlyDict is a base class. It's shouldn't be instantiated."
353-
)
354352

355353
_raise = kwargs.pop('_raise', True)
354+
if self._name is None:
355+
self.__dict__['_name'] = kwargs.pop('_name', None)
356356
self.__dict__['_parent'] = kwargs.pop('_parent', None)
357357
self.__dict__['_parent_key'] = kwargs.pop('_parent_key', None)
358358

359+
if self._name is None:
360+
raise exceptions.PlotlyError(
361+
"PlotlyDict is a base class. It's shouldn't be instantiated."
362+
)
363+
359364
super(PlotlyDict, self).__init__()
360365

361366
if self._name in graph_reference.TRACE_NAMES:

0 commit comments

Comments
 (0)