From a498a2d9b0d77bfbd0680ee65572ec33791c8a54 Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Tue, 7 Jan 2020 17:05:44 +0100 Subject: [PATCH] Drop support for mutable types as Dropdown options --- ipywidgets/widgets/tests/test_interaction.py | 34 ------------------- .../widgets/tests/test_widget_selection.py | 16 --------- ipywidgets/widgets/widget_selection.py | 20 ++++------- 3 files changed, 6 insertions(+), 64 deletions(-) diff --git a/ipywidgets/widgets/tests/test_interaction.py b/ipywidgets/widgets/tests/test_interaction.py index bf3d43e6c65..2134aedefda 100644 --- a/ipywidgets/widgets/tests/test_interaction.py +++ b/ipywidgets/widgets/tests/test_interaction.py @@ -182,40 +182,6 @@ def test_list_tuple_invalid(): print(bad) # because there is no custom message in assert_raises c = interactive(f, tup=bad) -def test_dict(): - for d in [ - dict(a=5), - dict(a=5, b='b', c=dict), - ]: - c = interactive(f, d=d) - w = c.children[0] - check = dict( - cls=widgets.Dropdown, - description='d', - value=next(iter(d.values())), - options=d, - _options_labels=tuple(d.keys()), - _options_values=tuple(d.values()), - ) - check_widget(w, **check) - - -def test_ordereddict(): - from collections import OrderedDict - items = [(3, 300), (1, 100), (2, 200)] - first = items[0][1] - values = OrderedDict(items) - c = interactive(f, lis=values) - assert len(c.children) == 2 - d = dict( - cls=widgets.Dropdown, - value=first, - options=values, - _options_labels=("3", "1", "2"), - _options_values=(300, 100, 200), - ) - check_widgets(c, lis=d) - def test_iterable(): def yield_values(): yield 3 diff --git a/ipywidgets/widgets/tests/test_widget_selection.py b/ipywidgets/widgets/tests/test_widget_selection.py index 83dc3a3c4cb..1b960c20f3e 100644 --- a/ipywidgets/widgets/tests/test_widget_selection.py +++ b/ipywidgets/widgets/tests/test_widget_selection.py @@ -1,8 +1,6 @@ # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. -import inspect -import warnings from unittest import TestCase from traitlets import TraitError @@ -15,20 +13,6 @@ class TestDropdown(TestCase): def test_construction(self): Dropdown() - def test_deprecation_warning_mapping_options(self): - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter("always") - - # Clearing the internal __warningregistry__ seems to be required for - # Python 2 (but not for Python 3) - module = inspect.getmodule(Dropdown) - getattr(module, '__warningregistry__', {}).clear() - - Dropdown(options={'One': 1, 'Two': 2, 'Three': 3}) - assert len(w) > 0 - assert issubclass(w[-1].category, DeprecationWarning) - assert "Support for mapping types has been deprecated" in str(w[-1].message) - class TestSelectionSlider(TestCase): diff --git a/ipywidgets/widgets/widget_selection.py b/ipywidgets/widgets/widget_selection.py index 4cadd6d14a4..0b1df364ee5 100644 --- a/ipywidgets/widgets/widget_selection.py +++ b/ipywidgets/widgets/widget_selection.py @@ -106,12 +106,6 @@ def _make_options(x): * an iterable of (label, value) pairs * an iterable of values, and labels will be generated """ - # Check if x is a mapping of labels to values - if isinstance(x, Mapping): - import warnings - warnings.warn("Support for mapping types has been deprecated and will be dropped in a future release.", DeprecationWarning) - return tuple((str(k), v) for k, v in x.items()) - # only iterate once through the options. xlist = tuple(x) @@ -132,10 +126,10 @@ def findvalue(array, value, compare = lambda x, y: x == y): class _Selection(DescriptionWidget, ValueWidget, CoreWidget): """Base class for Selection widgets - ``options`` can be specified as a list of values, list of (label, value) - tuples, or a dict of {label: value}. The labels are the strings that will be - displayed in the UI, representing the actual Python choices, and should be - unique. If labels are not specified, they are generated from the values. + ``options`` can be specified as a list of values or list of (label, value) + tuples. The labels are the strings that will be displayed in the UI, + representing the actual Python choices, and should be unique. + If labels are not specified, they are generated from the values. When programmatically setting the value, a reverse lookup is performed among the options to check that the value is valid. The reverse lookup uses @@ -149,7 +143,7 @@ class _Selection(DescriptionWidget, ValueWidget, CoreWidget): index = Int(None, help="Selected index", allow_none=True).tag(sync=True) options = Any((), - help="""Iterable of values, (label, value) pairs, or a mapping of {label: value} pairs that the user can select. + help="""Iterable of values or (label, value) pairs that the user can select. The labels are the strings that will be displayed in the UI, representing the actual Python choices, and should be unique. @@ -183,9 +177,7 @@ def __init__(self, *args, **kwargs): @validate('options') def _validate_options(self, proposal): - # if an iterator is provided, exhaust it - if isinstance(proposal.value, Iterable) and not isinstance(proposal.value, Mapping): - proposal.value = tuple(proposal.value) + proposal.value = tuple(proposal.value) # throws an error if there is a problem converting to full form self._options_full = _make_options(proposal.value) return proposal.value