From a4d1f4e99587deaeeae82db2715beda38a33fda7 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Tue, 12 Sep 2023 11:06:47 +0200 Subject: [PATCH] Use cbook methods for string checking --- lib/matplotlib/_mathtext.py | 2 +- lib/matplotlib/legend.py | 4 ++-- lib/matplotlib/rcsetup.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/_mathtext.py b/lib/matplotlib/_mathtext.py index b23cb67116ed..0d8842772a5b 100644 --- a/lib/matplotlib/_mathtext.py +++ b/lib/matplotlib/_mathtext.py @@ -2766,7 +2766,7 @@ def _auto_sized_delimiter(self, front: str, depth = max([x.depth for x in middle if not isinstance(x, str)]) factor = None for idx, el in enumerate(middle): - if isinstance(el, str) and el == '\\middle': + if el == r'\middle': c = T.cast(str, middle[idx + 1]) # Should be one of p.delims. if c != '.': middle[idx + 1] = AutoHeightChar( diff --git a/lib/matplotlib/legend.py b/lib/matplotlib/legend.py index fcd7850bb473..14249cb73442 100644 --- a/lib/matplotlib/legend.py +++ b/lib/matplotlib/legend.py @@ -29,7 +29,7 @@ import numpy as np import matplotlib as mpl -from matplotlib import _api, _docstring, colors, offsetbox +from matplotlib import _api, _docstring, cbook, colors, offsetbox from matplotlib.artist import Artist, allow_rasterization from matplotlib.cbook import silent_list from matplotlib.font_manager import FontProperties @@ -622,7 +622,7 @@ def __init__( break except AttributeError: pass - elif isinstance(labelcolor, str) and labelcolor == 'none': + elif cbook._str_equal(labelcolor, 'none'): for text in self.texts: text.set_color(labelcolor) elif np.iterable(labelcolor): diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 276bb9f812a9..c289459b1874 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -179,7 +179,7 @@ def _make_type_validator(cls, *, allow_none=False): def validator(s): if (allow_none and - (s is None or isinstance(s, str) and s.lower() == "none")): + (s is None or cbook._str_lower_equal(s, "none"))): return None if cls is str and not isinstance(s, str): raise ValueError(f'Could not convert {s!r} to str') @@ -615,7 +615,7 @@ def _validate_minor_tick_ndivs(n): two major ticks. """ - if isinstance(n, str) and n.lower() == 'auto': + if cbook._str_lower_equal(n, 'auto'): return n try: n = _validate_int_greaterequal0(n)