Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f084447

Browse files
committed
Add suggestions to ColorSequenceRegistry lookup errors
1 parent 3799e6b commit f084447

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

lib/matplotlib/colors.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,8 @@ def __init__(self):
142142
self._color_sequences = {**self._BUILTIN_COLOR_SEQUENCES}
143143

144144
def __getitem__(self, item):
145-
try:
146-
return list(self._color_sequences[item])
147-
except KeyError:
148-
raise KeyError(f"{item!r} is not a known color sequence name")
145+
return list(_api.getitem_checked(self._color_sequences, _error_cls=KeyError,
146+
sequence_name=item))
149147

150148
def __iter__(self):
151149
return iter(self._color_sequences)

lib/matplotlib/tests/test_colors.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,6 +1885,12 @@ def test_close_error_name():
18851885
r"'grays' is not a valid value for colormap\. "
18861886
r"Did you mean one of: 'gray', 'Grays', 'gray_r'\?")):
18871887
matplotlib.colormaps["grays"]
1888+
with pytest.raises(
1889+
KeyError,
1890+
match=(
1891+
"'set' is not a valid value for sequence_name. "
1892+
"Did you mean one of: 'Set3', 'Set2', 'Set1'?")):
1893+
matplotlib.color_sequences["set"]
18881894

18891895

18901896
def test_multi_norm_creation():

0 commit comments

Comments
 (0)