From 52a5dfdf7dc9dec580c015543e330253d44f1baf Mon Sep 17 00:00:00 2001 From: jsjeelshah Date: Fri, 22 Sep 2023 17:13:11 -0400 Subject: [PATCH] Remove deprecated code from _fontconfig_patterns --- doc/api/next_api_changes/removals/26884-JS.rst | 5 +++++ lib/matplotlib/_fontconfig_pattern.py | 13 ++----------- lib/matplotlib/tests/test_fontconfig_pattern.py | 2 +- 3 files changed, 8 insertions(+), 12 deletions(-) create mode 100644 doc/api/next_api_changes/removals/26884-JS.rst diff --git a/doc/api/next_api_changes/removals/26884-JS.rst b/doc/api/next_api_changes/removals/26884-JS.rst new file mode 100644 index 000000000000..71608b8d94be --- /dev/null +++ b/doc/api/next_api_changes/removals/26884-JS.rst @@ -0,0 +1,5 @@ +``parse_fontconfig_pattern`` raises on unknown constant names +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Previously, in a fontconfig pattern like ``DejaVu Sans:foo``, the unknown +``foo`` constant name would be silently ignored. This now raises an error. diff --git a/lib/matplotlib/_fontconfig_pattern.py b/lib/matplotlib/_fontconfig_pattern.py index d3933b9f396d..6802c6ae24d7 100644 --- a/lib/matplotlib/_fontconfig_pattern.py +++ b/lib/matplotlib/_fontconfig_pattern.py @@ -13,9 +13,7 @@ import re from pyparsing import ( - Group, Optional, ParseException, Regex, StringEnd, Suppress, ZeroOrMore) - -from matplotlib import _api + Optional, ParseException, Regex, StringEnd, Suppress, ZeroOrMore, oneOf) _family_punc = r'\\\-:,' @@ -63,8 +61,7 @@ def comma_separated(elem): size = Regex(r"([0-9]+\.?[0-9]*|\.[0-9]+)") name = Regex(r"[a-z]+") value = Regex(fr"([^{_value_punc}]|(\\[{_value_punc}]))*") - # replace trailing `| name` by oneOf(_CONSTANTS) in mpl 3.9. - prop = Group((name + Suppress("=") + comma_separated(value)) | name) + prop = (name + Suppress("=") + comma_separated(value)) | oneOf(_CONSTANTS) return ( Optional(comma_separated(family)("families")) + Optional("-" + comma_separated(size)("sizes")) @@ -97,12 +94,6 @@ def parse_fontconfig_pattern(pattern): props["size"] = [*parse["sizes"]] for prop in parse.get("properties", []): if len(prop) == 1: - if prop[0] not in _CONSTANTS: - _api.warn_deprecated( - "3.7", message=f"Support for unknown constants " - f"({prop[0]!r}) is deprecated since %(since)s and " - f"will be removed %(removal)s.") - continue prop = _CONSTANTS[prop[0]] k, *v = prop props.setdefault(k, []).extend(map(_value_unescape, v)) diff --git a/lib/matplotlib/tests/test_fontconfig_pattern.py b/lib/matplotlib/tests/test_fontconfig_pattern.py index 792a8ed517c2..496a35b95cf2 100644 --- a/lib/matplotlib/tests/test_fontconfig_pattern.py +++ b/lib/matplotlib/tests/test_fontconfig_pattern.py @@ -73,5 +73,5 @@ def test_fontconfig_str(): def test_fontconfig_unknown_constant(): - with pytest.warns(DeprecationWarning): + with pytest.raises(ValueError, match="ParseException"): FontProperties(":unknown")