Skip to content

Commit 1469268

Browse files
authored
Merge pull request #430 from plotly/allow-tuples
Allow Dash `children` to be a tuple instead of a list
2 parents 9312fe4 + 7f70192 commit 1469268

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.28.4 - 2018-10-18
2+
## Fixed
3+
- The `Component.traverse()` and `Component.traverse_with_paths()` methods now work correctly for components with `children` of type `tuple` (before, this only worked for `list`s). [#430](https://github.com/plotly/dash/pull/430)
4+
15
## 0.28.3 - 2018-10-17
26
## Fixed
37
- Fix http-equiv typo [#418](https://github.com/plotly/dash/pull/418)

Diff for: dash/dash.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -775,9 +775,10 @@ def _validate_value(val, index=None):
775775
)
776776

777777
# Children that are not of type Component or
778-
# collections.MutableSequence not returned by traverse
778+
# list/tuple not returned by traverse
779779
child = getattr(j, 'children', None)
780-
if not isinstance(child, collections.MutableSequence):
780+
if not isinstance(child, (tuple,
781+
collections.MutableSequence)):
781782
if child and not _value_is_valid(child):
782783
_raise_invalid(
783784
bad_val=child,
@@ -789,7 +790,7 @@ def _validate_value(val, index=None):
789790

790791
# Also check the child of val, as it will not be returned
791792
child = getattr(val, 'children', None)
792-
if not isinstance(child, collections.MutableSequence):
793+
if not isinstance(child, (tuple, collections.MutableSequence)):
793794
if child and not _value_is_valid(child):
794795
_raise_invalid(
795796
bad_val=child,

Diff for: dash/development/base_component.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def is_number(s):
1616
def _check_if_has_indexable_children(item):
1717
if (not hasattr(item, 'children') or
1818
(not isinstance(item.children, Component) and
19-
not isinstance(item.children, collections.MutableSequence))):
19+
not isinstance(item.children, (tuple,
20+
collections.MutableSequence)))):
2021

2122
raise KeyError
2223

@@ -145,7 +146,7 @@ def _get_set_or_delete(self, id, operation, new_item=None):
145146
pass
146147

147148
# if children is like a list
148-
if isinstance(self.children, collections.MutableSequence):
149+
if isinstance(self.children, (tuple, collections.MutableSequence)):
149150
for i, item in enumerate(self.children):
150151
# If the item itself is the one we're looking for
151152
if getattr(item, 'id', None) == id:
@@ -221,7 +222,7 @@ def traverse_with_paths(self):
221222
yield "\n".join(["[*] " + children_string, p]), t
222223

223224
# children is a list of components
224-
elif isinstance(children, collections.MutableSequence):
225+
elif isinstance(children, (tuple, collections.MutableSequence)):
225226
for idx, i in enumerate(children):
226227
list_path = "[{:d}] {:s} {}".format(
227228
idx,
@@ -254,7 +255,7 @@ def __len__(self):
254255
elif isinstance(self.children, Component):
255256
length = 1
256257
length += len(self.children)
257-
elif isinstance(self.children, collections.MutableSequence):
258+
elif isinstance(self.children, (tuple, collections.MutableSequence)):
258259
for c in self.children:
259260
length += 1
260261
if isinstance(c, Component):

Diff for: dash/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.28.3'
1+
__version__ = '0.28.4'

Diff for: tests/development/test_base_component.py

+10
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@ def test_traverse_with_nested_children_with_mixed_strings_and_without_lists(self
156156
c.children + [c3] + [c2] + c2.children
157157
)
158158

159+
def test_traverse_with_tuples(self): # noqa: E501
160+
c, c1, c2, c3, c4, c5 = nested_tree()
161+
c2.children = tuple(c2.children)
162+
c.children = tuple(c.children)
163+
elements = [i for i in c.traverse()]
164+
self.assertEqual(
165+
elements,
166+
list(c.children) + [c3] + [c2] + list(c2.children)
167+
)
168+
159169
def test_iter_with_nested_children_with_mixed_strings_and_without_lists(self): # noqa: E501
160170
c = nested_tree()[0]
161171
keys = list(c.keys())

0 commit comments

Comments
 (0)