Skip to content

Commit 7fde77e

Browse files
authored
Merge pull request #27685 from ksunden/pyparsing_warns
Work around pyparsing diagnostic warnings
2 parents 6368cc5 + f2124dd commit 7fde77e

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/matplotlib/_fontconfig_pattern.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import re
1414

1515
from pyparsing import (
16-
Optional, ParseException, Regex, StringEnd, Suppress, ZeroOrMore, oneOf)
16+
Group, Optional, ParseException, Regex, StringEnd, Suppress, ZeroOrMore, oneOf)
1717

1818

1919
_family_punc = r'\\\-:,'
@@ -61,7 +61,7 @@ def comma_separated(elem):
6161
size = Regex(r"([0-9]+\.?[0-9]*|\.[0-9]+)")
6262
name = Regex(r"[a-z]+")
6363
value = Regex(fr"([^{_value_punc}]|(\\[{_value_punc}]))*")
64-
prop = (name + Suppress("=") + comma_separated(value)) | oneOf(_CONSTANTS)
64+
prop = Group((name + Suppress("=") + comma_separated(value)) | oneOf(_CONSTANTS))
6565
return (
6666
Optional(comma_separated(family)("families"))
6767
+ Optional("-" + comma_separated(size)("sizes"))

lib/matplotlib/_mathtext.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -2030,10 +2030,18 @@ def csnames(group: str, names: Iterable[str]) -> Regex:
20302030
# elements is important for speed.)
20312031
p.auto_delim = Forward()
20322032
p.placeable = Forward()
2033+
p.named_placeable = Forward()
20332034
p.required_group = Forward()
20342035
p.optional_group = Forward()
20352036
p.token = Forward()
20362037

2038+
# Workaround for placable being part of a cycle of definitions
2039+
# calling `p.placeable("name")` results in a copy, so not guaranteed
2040+
# to get the definition added after it is used.
2041+
# ref https://github.com/matplotlib/matplotlib/issues/25204
2042+
# xref https://github.com/pyparsing/pyparsing/issues/95
2043+
p.named_placeable <<= p.placeable
2044+
20372045
set_names_and_parse_actions() # for mutually recursive definitions.
20382046

20392047
p.optional_group <<= "{" + ZeroOrMore(p.token)("group") + "}"
@@ -2043,7 +2051,7 @@ def csnames(group: str, names: Iterable[str]) -> Regex:
20432051

20442052
p.accent = (
20452053
csnames("accent", [*self._accent_map, *self._wide_accents])
2046-
- p.placeable("sym"))
2054+
- p.named_placeable("sym"))
20472055

20482056
p.function = csnames("name", self._function_names)
20492057

@@ -2089,7 +2097,7 @@ def csnames(group: str, names: Iterable[str]) -> Regex:
20892097
+ OneOrMore(oneOf(["_", "^"]) - p.placeable)("subsuper")
20902098
+ Regex("'*")("apostrophes"))
20912099
| Regex("'+")("apostrophes")
2092-
| (p.placeable("nucleus") + Regex("'*")("apostrophes"))
2100+
| (p.named_placeable("nucleus") + Regex("'*")("apostrophes"))
20932101
)
20942102

20952103
p.simple = p.space | p.customspace | p.font | p.subsuper

0 commit comments

Comments
 (0)