Skip to content

Commit a498a2d

Browse files
committed
Drop support for mutable types as Dropdown options
1 parent e643166 commit a498a2d

File tree

3 files changed

+6
-64
lines changed

3 files changed

+6
-64
lines changed

ipywidgets/widgets/tests/test_interaction.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -182,40 +182,6 @@ def test_list_tuple_invalid():
182182
print(bad) # because there is no custom message in assert_raises
183183
c = interactive(f, tup=bad)
184184

185-
def test_dict():
186-
for d in [
187-
dict(a=5),
188-
dict(a=5, b='b', c=dict),
189-
]:
190-
c = interactive(f, d=d)
191-
w = c.children[0]
192-
check = dict(
193-
cls=widgets.Dropdown,
194-
description='d',
195-
value=next(iter(d.values())),
196-
options=d,
197-
_options_labels=tuple(d.keys()),
198-
_options_values=tuple(d.values()),
199-
)
200-
check_widget(w, **check)
201-
202-
203-
def test_ordereddict():
204-
from collections import OrderedDict
205-
items = [(3, 300), (1, 100), (2, 200)]
206-
first = items[0][1]
207-
values = OrderedDict(items)
208-
c = interactive(f, lis=values)
209-
assert len(c.children) == 2
210-
d = dict(
211-
cls=widgets.Dropdown,
212-
value=first,
213-
options=values,
214-
_options_labels=("3", "1", "2"),
215-
_options_values=(300, 100, 200),
216-
)
217-
check_widgets(c, lis=d)
218-
219185
def test_iterable():
220186
def yield_values():
221187
yield 3

ipywidgets/widgets/tests/test_widget_selection.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Copyright (c) Jupyter Development Team.
22
# Distributed under the terms of the Modified BSD License.
33

4-
import inspect
5-
import warnings
64
from unittest import TestCase
75

86
from traitlets import TraitError
@@ -15,20 +13,6 @@ class TestDropdown(TestCase):
1513
def test_construction(self):
1614
Dropdown()
1715

18-
def test_deprecation_warning_mapping_options(self):
19-
with warnings.catch_warnings(record=True) as w:
20-
warnings.simplefilter("always")
21-
22-
# Clearing the internal __warningregistry__ seems to be required for
23-
# Python 2 (but not for Python 3)
24-
module = inspect.getmodule(Dropdown)
25-
getattr(module, '__warningregistry__', {}).clear()
26-
27-
Dropdown(options={'One': 1, 'Two': 2, 'Three': 3})
28-
assert len(w) > 0
29-
assert issubclass(w[-1].category, DeprecationWarning)
30-
assert "Support for mapping types has been deprecated" in str(w[-1].message)
31-
3216

3317
class TestSelectionSlider(TestCase):
3418

ipywidgets/widgets/widget_selection.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,6 @@ def _make_options(x):
106106
* an iterable of (label, value) pairs
107107
* an iterable of values, and labels will be generated
108108
"""
109-
# Check if x is a mapping of labels to values
110-
if isinstance(x, Mapping):
111-
import warnings
112-
warnings.warn("Support for mapping types has been deprecated and will be dropped in a future release.", DeprecationWarning)
113-
return tuple((str(k), v) for k, v in x.items())
114-
115109
# only iterate once through the options.
116110
xlist = tuple(x)
117111

@@ -132,10 +126,10 @@ def findvalue(array, value, compare = lambda x, y: x == y):
132126
class _Selection(DescriptionWidget, ValueWidget, CoreWidget):
133127
"""Base class for Selection widgets
134128
135-
``options`` can be specified as a list of values, list of (label, value)
136-
tuples, or a dict of {label: value}. The labels are the strings that will be
137-
displayed in the UI, representing the actual Python choices, and should be
138-
unique. If labels are not specified, they are generated from the values.
129+
``options`` can be specified as a list of values or list of (label, value)
130+
tuples. The labels are the strings that will be displayed in the UI,
131+
representing the actual Python choices, and should be unique.
132+
If labels are not specified, they are generated from the values.
139133
140134
When programmatically setting the value, a reverse lookup is performed
141135
among the options to check that the value is valid. The reverse lookup uses
@@ -149,7 +143,7 @@ class _Selection(DescriptionWidget, ValueWidget, CoreWidget):
149143
index = Int(None, help="Selected index", allow_none=True).tag(sync=True)
150144

151145
options = Any((),
152-
help="""Iterable of values, (label, value) pairs, or a mapping of {label: value} pairs that the user can select.
146+
help="""Iterable of values or (label, value) pairs that the user can select.
153147
154148
The labels are the strings that will be displayed in the UI, representing the
155149
actual Python choices, and should be unique.
@@ -183,9 +177,7 @@ def __init__(self, *args, **kwargs):
183177

184178
@validate('options')
185179
def _validate_options(self, proposal):
186-
# if an iterator is provided, exhaust it
187-
if isinstance(proposal.value, Iterable) and not isinstance(proposal.value, Mapping):
188-
proposal.value = tuple(proposal.value)
180+
proposal.value = tuple(proposal.value)
189181
# throws an error if there is a problem converting to full form
190182
self._options_full = _make_options(proposal.value)
191183
return proposal.value

0 commit comments

Comments
 (0)