FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Use PEP8 style method and function names from pyparsing by dstansby · Pull Request #29745 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (2) .toml  (1) .txt  (2) .yml  (1) All 5 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 4 additions & 0 deletions doc/api/next_api_changes/development/29745-DS.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
New minimum version of pyparsing
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The minimum required version of ``pyparsing`` has been updated from 2.3.1 to 3.0.0.
2 changes: 1 addition & 1 deletion doc/install/dependencies.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ reference.
* `NumPy <https://numpy.org>`_ (>= 1.23)
* `packaging <https://pypi.org/project/packaging/>`_ (>= 20.0)
* `Pillow <https://pillow.readthedocs.io/en/latest/>`_ (>= 9.0)
* `pyparsing <https://pypi.org/project/pyparsing/>`_ (>= 2.3.1)
* `pyparsing <https://pypi.org/project/pyparsing/>`_ (>= 3)


.. _optional_dependencies:
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dependencies:
- pillow>=9
- pkg-config
- pygobject
- pyparsing>=2.3.1
- pyparsing>=3
- pyqt
- python>=3.10
- python-dateutil>=2.1
Expand Down
8 changes: 4 additions & 4 deletions lib/matplotlib/_fontconfig_pattern.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import re

from pyparsing import (
Group, Optional, ParseException, Regex, StringEnd, Suppress, ZeroOrMore, oneOf)
Group, Optional, ParseException, Regex, StringEnd, Suppress, ZeroOrMore, one_of)


_family_punc = r'\\\-:,'
Expand Down Expand Up @@ -61,7 +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}]))*")
prop = Group((name + Suppress("=") + comma_separated(value)) | oneOf(_CONSTANTS))
prop = Group((name + Suppress("=") + comma_separated(value)) | one_of(_CONSTANTS))
return (
Optional(comma_separated(family)("families"))
+ Optional("-" + comma_separated(size)("sizes"))
Expand All @@ -82,11 +82,11 @@ def parse_fontconfig_pattern(pattern):
"""
parser = _make_fontconfig_parser()
try:
parse = parser.parseString(pattern)
parse = parser.parse_string(pattern)
except ParseException as err:
# explain becomes a plain method on pyparsing 3 (err.explain(0)).
raise ValueError("\n" + ParseException.explain(err, 0)) from None
parser.resetCache()
parser.reset_cache()
props = {}
if "families" in parse:
props["family"] = [*map(_family_unescape, parse["families"])]
Expand Down
50 changes: 22 additions & 28 deletions lib/matplotlib/_mathtext.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

import numpy as np
from pyparsing import (
Empty, Forward, Literal, NotAny, oneOf, OneOrMore, Optional,
Empty, Forward, Literal, Group, NotAny, OneOrMore, Optional,
ParseBaseException, ParseException, ParseExpression, ParseFatalException,
ParserElement, ParseResults, QuotedString, Regex, StringEnd, ZeroOrMore,
pyparsing_common, Group)
pyparsing_common, nested_expr, one_of)

import matplotlib as mpl
from . import cbook
Expand All @@ -31,18 +31,12 @@
from .font_manager import FontProperties, findfont, get_font
from .ft2font import FT2Font, FT2Image, Kerning, LoadFlags

from packaging.version import parse as parse_version
from pyparsing import __version__ as pyparsing_version
if parse_version(pyparsing_version).major < 3:
from pyparsing import nestedExpr as nested_expr
else:
from pyparsing import nested_expr

if T.TYPE_CHECKING:
from collections.abc import Iterable
from .ft2font import Glyph

ParserElement.enablePackrat()
ParserElement.enable_packrat()
_log = logging.getLogger("matplotlib.mathtext")


Expand Down Expand Up @@ -1745,7 +1739,7 @@ def Error(msg: str) -> ParserElement:
def raise_error(s: str, loc: int, toks: ParseResults) -> T.Any:
raise ParseFatalException(s, loc, msg)

return Empty().setParseAction(raise_error)
return Empty().set_parse_action(raise_error)


class ParserState:
Expand Down Expand Up @@ -1981,10 +1975,10 @@ def set_names_and_parse_actions() -> None:
# token, placeable, and auto_delim are forward references which
# are left without names to ensure useful error messages
if key not in ("token", "placeable", "auto_delim"):
val.setName(key)
val.set_name(key)
# Set actions
if hasattr(self, key):
val.setParseAction(getattr(self, key))
val.set_parse_action(getattr(self, key))

# Root definitions.

Expand All @@ -2007,24 +2001,24 @@ def csnames(group: str, names: Iterable[str]) -> Regex:
)

p.float_literal = Regex(r"[-+]?([0-9]+\.?[0-9]*|\.[0-9]+)")
p.space = oneOf(self._space_widths)("space")
p.space = one_of(self._space_widths)("space")

p.style_literal = oneOf(
p.style_literal = one_of(
[str(e.value) for e in self._MathStyle])("style_literal")

p.symbol = Regex(
r"[a-zA-Z0-9 +\-*/<>=:,.;!\?&'@()\[\]|\U00000080-\U0001ffff]"
r"|\\[%${}\[\]_|]"
+ r"|\\(?:{})(?![A-Za-z])".format(
"|".join(map(re.escape, tex2uni)))
)("sym").leaveWhitespace()
)("sym").leave_whitespace()
p.unknown_symbol = Regex(r"\\[A-Za-z]+")("name")

p.font = csnames("font", self._fontnames)
p.start_group = Optional(r"\math" + oneOf(self._fontnames)("font")) + "{"
p.start_group = Optional(r"\math" + one_of(self._fontnames)("font")) + "{"
p.end_group = Literal("}")

p.delim = oneOf(self._delims)
p.delim = one_of(self._delims)

# Mutually recursive definitions. (Minimizing the number of Forward
# elements is important for speed.)
Expand Down Expand Up @@ -2085,7 +2079,7 @@ def csnames(group: str, names: Iterable[str]) -> Regex:
r"\underset",
p.optional_group("annotation") + p.optional_group("body"))

p.text = cmd(r"\text", QuotedString('{', '\\', endQuoteChar="}"))
p.text = cmd(r"\text", QuotedString('{', '\\', end_quote_char="}"))

p.substack = cmd(r"\substack",
nested_expr(opener="{", closer="}",
Expand All @@ -2094,7 +2088,7 @@ def csnames(group: str, names: Iterable[str]) -> Regex:

p.subsuper = (
(Optional(p.placeable)("nucleus")
+ OneOrMore(oneOf(["_", "^"]) - p.placeable)("subsuper")
+ OneOrMore(one_of(["_", "^"]) - p.placeable)("subsuper")
+ Regex("'*")("apostrophes"))
| Regex("'+")("apostrophes")
| (p.named_placeable("nucleus") + Regex("'*")("apostrophes"))
Expand Down Expand Up @@ -2143,8 +2137,8 @@ def csnames(group: str, names: Iterable[str]) -> Regex:

# Leaf definitions.
p.math = OneOrMore(p.token)
p.math_string = QuotedString('$', '\\', unquoteResults=False)
p.non_math = Regex(r"(?:(?:\\[$])|[^$])*").leaveWhitespace()
p.math_string = QuotedString('$', '\\', unquote_results=False)
p.non_math = Regex(r"(?:(?:\\[$])|[^$])*").leave_whitespace()
p.main = (
p.non_math + ZeroOrMore(p.math_string + p.non_math) + StringEnd()
)
Expand All @@ -2167,15 +2161,15 @@ def parse(self, s: str, fonts_object: Fonts, fontsize: float, dpi: float) -> Hli
ParserState(fonts_object, 'default', 'rm', fontsize, dpi)]
self._em_width_cache: dict[tuple[str, float, float], float] = {}
try:
result = self._expression.parseString(s)
result = self._expression.parse_string(s)
except ParseBaseException as err:
# explain becomes a plain method on pyparsing 3 (err.explain(0)).
raise ValueError("\n" + ParseException.explain(err, 0)) from None
self._state_stack = []
self._in_subscript_or_superscript = False
# prevent operator spacing from leaking into a new expression
self._em_width_cache = {}
ParserElement.resetCache()
ParserElement.reset_cache()
return T.cast(Hlist, result[0]) # Known return type from main.

def get_state(self) -> ParserState:
Expand All @@ -2191,13 +2185,13 @@ def push_state(self) -> None:
self._state_stack.append(self.get_state().copy())

def main(self, toks: ParseResults) -> list[Hlist]:
return [Hlist(toks.asList())]
return [Hlist(toks.as_list())]

def math_string(self, toks: ParseResults) -> ParseResults:
return self._math_expression.parseString(toks[0][1:-1], parseAll=True)
return self._math_expression.parse_string(toks[0][1:-1], parse_all=True)

def math(self, toks: ParseResults) -> T.Any:
hlist = Hlist(toks.asList())
hlist = Hlist(toks.as_list())
self.pop_state()
return [hlist]

Expand All @@ -2210,7 +2204,7 @@ def non_math(self, toks: ParseResults) -> T.Any:
self.get_state().font = mpl.rcParams['mathtext.default']
return [hlist]

float_literal = staticmethod(pyparsing_common.convertToFloat)
float_literal = staticmethod(pyparsing_common.convert_to_float)

def text(self, toks: ParseResults) -> T.Any:
self.push_state()
Expand Down Expand Up @@ -2809,7 +2803,7 @@ def auto_delim(self, toks: ParseResults) -> T.Any:
return self._auto_sized_delimiter(
toks["left"],
# if "mid" in toks ... can be removed when requiring pyparsing 3.
toks["mid"].asList() if "mid" in toks else [],
toks["mid"].as_list() if "mid" in toks else [],
toks["right"])

def boldsymbol(self, toks: ParseResults) -> T.Any:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencies = [
"numpy >= 1.23",
"packaging >= 20.0",
"pillow >= 9",
"pyparsing >= 2.3.1",
"pyparsing >= 3",
"python-dateutil >= 2.7",
]
requires-python = ">=3.10"
Expand Down
2 changes: 1 addition & 1 deletion requirements/testing/minver.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ meson==1.1.0
numpy==1.23.0
packaging==20.0
pillow==9.0.1
pyparsing==2.3.1
pyparsing==3.0.0
pytest==7.0.0
python-dateutil==2.7

Expand Down
2 changes: 1 addition & 1 deletion requirements/testing/mypy.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fonttools>=4.22.0
kiwisolver>=1.3.1
packaging>=20.0
pillow>=9
pyparsing>=2.3.1
pyparsing>=3
python-dateutil>=2.7
setuptools_scm>=7
setuptools>=64

Back | FazBrowse Home | New Git URL