Skip to content

Commit ac2032d

Browse files
authored
Merge pull request #2775 from hickmanw/widget_selection
fix misnamed attribute in _MultipleSelection
2 parents b91a6d9 + cab25ca commit ac2032d

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

ipywidgets/widgets/widget_selection.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@
9494
"""
9595

9696

97+
def _exhaust_iterable(x):
98+
"""Exhaust any non-mapping iterable into a tuple"""
99+
if isinstance(x, Iterable) and not isinstance(x, Mapping):
100+
return tuple(x)
101+
return x
102+
103+
97104
def _make_options(x):
98105
"""Standardize the options tuple format.
99106
@@ -161,13 +168,13 @@ def __init__(self, *args, **kwargs):
161168
# We have to make the basic options bookkeeping consistent
162169
# so we don't have errors the first time validators run
163170
self._initializing_traits_ = True
164-
options = _make_options(kwargs.get('options', ()))
165-
self._options_full = options
166-
self.set_trait('_options_labels', tuple(i[0] for i in options))
167-
self._options_values = tuple(i[1] for i in options)
171+
kwargs['options'] = _exhaust_iterable(kwargs.get('options', ()))
172+
self._options_full = _make_options(kwargs['options'])
173+
self._propagate_options(None)
168174

169175
# Select the first item by default, if we can
170176
if 'index' not in kwargs and 'value' not in kwargs and 'label' not in kwargs:
177+
options = self._options_full
171178
nonempty = (len(options) > 0)
172179
kwargs['index'] = 0 if nonempty else None
173180
kwargs['label'], kwargs['value'] = options[0] if nonempty else (None, None)
@@ -178,8 +185,7 @@ def __init__(self, *args, **kwargs):
178185
@validate('options')
179186
def _validate_options(self, proposal):
180187
# if an iterator is provided, exhaust it
181-
if isinstance(proposal.value, Iterable) and not isinstance(proposal.value, Mapping):
182-
proposal.value = tuple(proposal.value)
188+
proposal.value = _exhaust_iterable(proposal.value)
183189
# throws an error if there is a problem converting to full form
184190
self._options_full = _make_options(proposal.value)
185191
return proposal.value
@@ -303,18 +309,16 @@ def __init__(self, *args, **kwargs):
303309
# We have to make the basic options bookkeeping consistent
304310
# so we don't have errors the first time validators run
305311
self._initializing_traits_ = True
306-
options = _make_options(kwargs.get('options', ()))
307-
self._full_options = options
308-
self.set_trait('_options_labels', tuple(i[0] for i in options))
309-
self._options_values = tuple(i[1] for i in options)
312+
kwargs['options'] = _exhaust_iterable(kwargs.get('options', ()))
313+
self._options_full = _make_options(kwargs['options'])
314+
self._propagate_options(None)
310315

311316
super().__init__(*args, **kwargs)
312317
self._initializing_traits_ = False
313318

314319
@validate('options')
315320
def _validate_options(self, proposal):
316-
if isinstance(proposal.value, Iterable) and not isinstance(proposal.value, Mapping):
317-
proposal.value = tuple(proposal.value)
321+
proposal.value = _exhaust_iterable(proposal.value)
318322
# throws an error if there is a problem converting to full form
319323
self._options_full = _make_options(proposal.value)
320324
return proposal.value
@@ -516,8 +520,7 @@ def __init__(self, *args, **kwargs):
516520

517521
@validate('options')
518522
def _validate_options(self, proposal):
519-
if isinstance(proposal.value, Iterable) and not isinstance(proposal.value, Mapping):
520-
proposal.value = tuple(proposal.value)
523+
proposal.value = _exhaust_iterable(proposal.value)
521524
self._options_full = _make_options(proposal.value)
522525
if len(self._options_full) == 0:
523526
raise TraitError("Option list must be nonempty")
@@ -540,8 +543,7 @@ def __init__(self, *args, **kwargs):
540543

541544
@validate('options')
542545
def _validate_options(self, proposal):
543-
if isinstance(proposal.value, Iterable) and not isinstance(proposal.value, Mapping):
544-
proposal.value = tuple(proposal.value)
546+
proposal.value = _exhaust_iterable(proposal.value)
545547
# throws an error if there is a problem converting to full form
546548
self._options_full = _make_options(proposal.value)
547549
if len(self._options_full) == 0:

0 commit comments

Comments
 (0)