diff --git a/lib/matplotlib/hatch.py b/lib/matplotlib/hatch.py index 9ec88776cfd3..992df2d90bb7 100644 --- a/lib/matplotlib/hatch.py +++ b/lib/matplotlib/hatch.py @@ -2,7 +2,6 @@ import numpy as np -from matplotlib import _api from matplotlib.path import Path @@ -180,20 +179,18 @@ def __init__(self, hatch, density): def _validate_hatch_pattern(hatch): - valid_hatch_patterns = set(r'-+|/\xXoO.*') + valid_hatch_patterns = set(r'-+|/\\xXoO.*') if hatch is not None: + if not isinstance(hatch, str): + raise ValueError("Hatch pattern must be a string") invalids = set(hatch).difference(valid_hatch_patterns) if invalids: valid = ''.join(sorted(valid_hatch_patterns)) invalids = ''.join(sorted(invalids)) - _api.warn_deprecated( - '3.4', - removal='3.9', # one release after custom hatches (#20690) - message=f'hatch must consist of a string of "{valid}" or ' - 'None, but found the following invalid values ' - f'"{invalids}". Passing invalid values is deprecated ' - 'since %(since)s and will become an error %(removal)s.' - ) + message = f"""Unknown hatch symbol(s): {invalids}. + Hatch must consist of a string of {valid}""" + raise ValueError(message) + return hatch def get_path(hatchpattern, density=6): diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 38d4606024d3..f9d05a95e642 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -22,6 +22,7 @@ import numpy as np +from matplotlib.hatch import _validate_hatch_pattern from matplotlib import _api, cbook from matplotlib.cbook import ls_mapper from matplotlib.colors import Colormap, is_color_like @@ -592,19 +593,7 @@ def _validate_int_greaterequal0(s): raise RuntimeError(f'Value must be >=0; got {s}') -def validate_hatch(s): - r""" - Validate a hatch pattern. - A hatch pattern string can have any sequence of the following - characters: ``\ / | - + * . x o O``. - """ - if not isinstance(s, str): - raise ValueError("Hatch pattern must be a string") - _api.check_isinstance(str, hatch_pattern=s) - unknown = set(s) - {'\\', '/', '|', '-', '+', '*', '.', 'x', 'o', 'O'} - if unknown: - raise ValueError("Unknown hatch symbol(s): %s" % list(unknown)) - return s +validate_hatch = _validate_hatch_pattern validate_hatchlist = _listify_validator(validate_hatch) diff --git a/lib/matplotlib/tests/test_rcparams.py b/lib/matplotlib/tests/test_rcparams.py index 65cd823f13a9..4635c6b5f44e 100644 --- a/lib/matplotlib/tests/test_rcparams.py +++ b/lib/matplotlib/tests/test_rcparams.py @@ -311,10 +311,9 @@ def generate_validator_testcases(valid): }, {'validator': validate_hatch, 'success': (('--|', '--|'), ('\\oO', '\\oO'), - ('/+*/.x', '/+*/.x'), ('', '')), + ('/+*/.xX', '/+*/.xX'), ('', '')), 'fail': (('--_', ValueError), - (8, ValueError), - ('X', ValueError)), + (8, ValueError),), }, {'validator': validate_colorlist, 'success': (('r,g,b', ['r', 'g', 'b']),