diff --git a/doc/api/next_api_changes/behaviour.rst b/doc/api/next_api_changes/behaviour.rst index d7bce770b3f4..87f2531119c2 100644 --- a/doc/api/next_api_changes/behaviour.rst +++ b/doc/api/next_api_changes/behaviour.rst @@ -100,4 +100,9 @@ deprecation warning. Previously setting the *ecolor* would turn off automatic color cycling for the plot, leading to the the lines and markers defaulting to whatever the first color in the color cycle was in the case of -multiple plot calls. \ No newline at end of file +multiple plot calls. + +`.rcsetup.validate_color_for_prop_cycle` now always raises TypeError for bytes input +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +It previously raised `TypeError`, **except** when the input was of the form +``b"C[number]"`` in which case it raised a ValueError. diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 9eefcccdcbc7..9fe079900a91 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -322,18 +322,9 @@ def validate_color_or_auto(s): def validate_color_for_prop_cycle(s): - # Special-case the N-th color cycle syntax, this obviously can not - # go in the color cycle. - if isinstance(s, bytes): - match = re.match(b'^C[0-9]$', s) - if match is not None: - raise ValueError('Can not put cycle reference ({cn!r}) in ' - 'prop_cycler'.format(cn=s)) - elif isinstance(s, str): - match = re.match('^C[0-9]$', s) - if match is not None: - raise ValueError('Can not put cycle reference ({cn!r}) in ' - 'prop_cycler'.format(cn=s)) + # N-th color cycle syntax can't go into the color cycle. + if isinstance(s, str) and re.match("^C[0-9]$", s): + raise ValueError(f"Cannot put cycle reference ({s!r}) in prop_cycler") return validate_color(s)