diff --git a/doc/api/next_api_changes/removals/28076-SP.rst b/doc/api/next_api_changes/removals/28076-SP.rst new file mode 100644 index 000000000000..726f3d66048b --- /dev/null +++ b/doc/api/next_api_changes/removals/28076-SP.rst @@ -0,0 +1,4 @@ +``hatch.validate_hatch`` +~~~~~~~~~~~~~~~~~~~~~~~~ +Removal of deprecation warning for invalid hatch patterns +in hatch module. diff --git a/lib/matplotlib/hatch.py b/lib/matplotlib/hatch.py index 9ec88776cfd3..dba7b0763e9f 100644 --- a/lib/matplotlib/hatch.py +++ b/lib/matplotlib/hatch.py @@ -2,8 +2,8 @@ import numpy as np -from matplotlib import _api from matplotlib.path import Path +from matplotlib.rcsetup import validate_hatch class HatchPatternBase: @@ -179,21 +179,7 @@ def __init__(self, hatch, density): ] -def _validate_hatch_pattern(hatch): - valid_hatch_patterns = set(r'-+|/\xXoO.*') - if hatch is not None: - 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.' - ) +_validate_hatch_pattern = validate_hatch def get_path(hatchpattern, density=6): diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index a326d22f039a..b54914a2d7a3 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -623,13 +623,14 @@ def validate_hatch(s): 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 + if s is not None: + if not isinstance(s, str): + raise ValueError("Hatch pattern must be a string") + _api.check_isinstance(str, hatch_pattern=s) + unknown = set(s) - {'\\', '/', '|', '-', '+', '*', '.', 'x', 'X', 'o', 'O'} + if unknown: + raise ValueError("Unknown hatch symbol(s): %s" % list(unknown)) + return s validate_hatchlist = _listify_validator(validate_hatch) diff --git a/lib/matplotlib/tests/test_rcparams.py b/lib/matplotlib/tests/test_rcparams.py index 4823df0ce250..9a40d232bd0d 100644 --- a/lib/matplotlib/tests/test_rcparams.py +++ b/lib/matplotlib/tests/test_rcparams.py @@ -311,8 +311,7 @@ def generate_validator_testcases(valid): 'success': (('--|', '--|'), ('\\oO', '\\oO'), ('/+*/.x', '/+*/.x'), ('', '')), 'fail': (('--_', ValueError), - (8, ValueError), - ('X', ValueError)), + (8, ValueError)), }, {'validator': validate_colorlist, 'success': (('r,g,b', ['r', 'g', 'b']),