Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Remove deprecated code from _fontconfig_patterns #26884

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/api/next_api_changes/removals/26884-JS.rst
Original file line number Diff line number Diff line change
@@ -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.
13 changes: 2 additions & 11 deletions lib/matplotlib/_fontconfig_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'\\\-:,'
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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
Comment on lines -101 to -105
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should raise an error now.

prop = _CONSTANTS[prop[0]]
k, *v = prop
props.setdefault(k, []).extend(map(_value_unescape, v))
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_fontconfig_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")