Skip to content

Commit

Permalink
Merge pull request #3556 from jasongrout/optionwarning
Browse files Browse the repository at this point in the history
Make the selection widgets mapping options error more helpful.
  • Loading branch information
vidartf committed Aug 23, 2022
2 parents 58adde2 + 5536885 commit 8e335ad
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 1 addition & 2 deletions docs/source/user_migration_guides.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ For these, it is no longer possible to use `dict`s or other mapping types as val
`options` trait. Using mapping types in this way has been deprecated since version 7.4, and
will now raise a `TypeError`.

Suggested migration: Clean up the `options` use. The following snippet can be used to convert
a `dict` to the new format: `w.options = tuple((str(k), v) for k, v in your_dict.items())`.
Suggested migration: Instead of using a dict `my_dict` as options, use `my_dict.items()`, which returns the items in `my_dict` as key-value pairs. For example, `Select(options=my_dict.items())`.

#### Description Sanitization

Expand Down
2 changes: 1 addition & 1 deletion python/ipywidgets/ipywidgets/widgets/widget_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def _make_options(x):
* an iterable of values, and labels will be generated
"""
if isinstance(x, Mapping):
raise TypeError("options must be a list of values or a list of (label, value) tuples")
raise TypeError("options must be a iterable of values or of (label, value) pairs. If x is your Mapping, use x.items() for the options.")

# only iterate once through the options.
xlist = tuple(x)
Expand Down

0 comments on commit 8e335ad

Please sign in to comment.