From c5c0f493e4ad7a2c52cca3cc70761b07d3df174e Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Thu, 13 Feb 2020 01:20:18 +0100 Subject: [PATCH] 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). --- doc/api/next_api_changes/behaviour.rst | 7 ++++++- lib/matplotlib/rcsetup.py | 15 +++------------ 2 files changed, 9 insertions(+), 13 deletions(-) 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)