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

Skip to content

Commit c5c0f49

Browse files
committed
Simplify validate_color_for_prop_cycle.
No need to special case bytes -- validate_colors is going to raise a TypeError on bytes input anyways (_is_nth_color checks that the input is str as well).
1 parent 32d3306 commit c5c0f49

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

doc/api/next_api_changes/behaviour.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,9 @@ deprecation warning.
100100

101101
Previously setting the *ecolor* would turn off automatic color cycling for the plot, leading to the
102102
the lines and markers defaulting to whatever the first color in the color cycle was in the case of
103-
multiple plot calls.
103+
multiple plot calls.
104+
105+
`.rcsetup.validate_color_for_prop_cycle` now always raises TypeError for bytes input
106+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
107+
It previously raised `TypeError`, **except** when the input was of the form
108+
``b"C[number]"`` in which case it raised a ValueError.

lib/matplotlib/rcsetup.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -322,18 +322,9 @@ def validate_color_or_auto(s):
322322

323323

324324
def validate_color_for_prop_cycle(s):
325-
# Special-case the N-th color cycle syntax, this obviously can not
326-
# go in the color cycle.
327-
if isinstance(s, bytes):
328-
match = re.match(b'^C[0-9]$', s)
329-
if match is not None:
330-
raise ValueError('Can not put cycle reference ({cn!r}) in '
331-
'prop_cycler'.format(cn=s))
332-
elif isinstance(s, str):
333-
match = re.match('^C[0-9]$', s)
334-
if match is not None:
335-
raise ValueError('Can not put cycle reference ({cn!r}) in '
336-
'prop_cycler'.format(cn=s))
325+
# N-th color cycle syntax can't go into the color cycle.
326+
if isinstance(s, str) and re.match("^C[0-9]$", s):
327+
raise ValueError(f"Cannot put cycle reference ({s!r}) in prop_cycler")
337328
return validate_color(s)
338329

339330

0 commit comments

Comments
 (0)