Skip to content

Commit 0395c50

Browse files
committed
Intermediate changes
commit_hash:16645c680befa673cec2481eceae5781024fdb0e
1 parent ca6fbaf commit 0395c50

File tree

10 files changed

+165
-83
lines changed

10 files changed

+165
-83
lines changed

contrib/python/pyparsing/py3/.dist-info/METADATA

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 2.1
22
Name: pyparsing
3-
Version: 3.2.0
3+
Version: 3.2.1
44
Summary: pyparsing module - Classes and methods to define and execute parsing grammars
55
Author-email: Paul McGuire <ptmcg.gm+pyparsing@gmail.com>
66
Requires-Python: >=3.9

contrib/python/pyparsing/py3/pyparsing/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ def __repr__(self):
120120
return f"{__name__}.{type(self).__name__}({', '.join('{}={!r}'.format(*nv) for nv in zip(self._fields, self))})"
121121

122122

123-
__version_info__ = version_info(3, 2, 0, "final", 1)
124-
__version_time__ = "13 Oct 2024 09:46 UTC"
123+
__version_info__ = version_info(3, 2, 1, "final", 1)
124+
__version_time__ = "31 Dec 2024 20:41 UTC"
125125
__version__ = __version_info__.__version__
126126
__versionTime__ = __version_time__
127127
__author__ = "Paul McGuire <ptmcg.gm+pyparsing@gmail.com>"

contrib/python/pyparsing/py3/pyparsing/actions.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
# actions.py
2+
from __future__ import annotations
3+
4+
from typing import Union, Callable, Any
25

36
from .exceptions import ParseException
47
from .util import col, replaced_by_pep8
8+
from .results import ParseResults
9+
10+
11+
ParseAction = Union[
12+
Callable[[], Any],
13+
Callable[[ParseResults], Any],
14+
Callable[[int, ParseResults], Any],
15+
Callable[[str, int, ParseResults], Any],
16+
]
517

618

719
class OnlyOnce:
820
"""
921
Wrapper for parse actions, to ensure they are only called once.
22+
Note: parse action signature must include all 3 arguments.
1023
"""
1124

12-
def __init__(self, method_call):
25+
def __init__(self, method_call: Callable[[str, int, ParseResults], Any]):
1326
from .core import _trim_arity
1427

1528
self.callable = _trim_arity(method_call)
1629
self.called = False
1730

18-
def __call__(self, s, l, t):
31+
def __call__(self, s: str, l: int, t: ParseResults) -> ParseResults:
1932
if not self.called:
2033
results = self.callable(s, l, t)
2134
self.called = True
@@ -30,20 +43,20 @@ def reset(self):
3043
self.called = False
3144

3245

33-
def match_only_at_col(n):
46+
def match_only_at_col(n: int) -> ParseAction:
3447
"""
3548
Helper method for defining parse actions that require matching at
3649
a specific column in the input text.
3750
"""
3851

39-
def verify_col(strg, locn, toks):
52+
def verify_col(strg: str, locn: int, toks: ParseResults) -> None:
4053
if col(locn, strg) != n:
4154
raise ParseException(strg, locn, f"matched token not at column {n}")
4255

4356
return verify_col
4457

4558

46-
def replace_with(repl_str):
59+
def replace_with(repl_str: str) -> ParseAction:
4760
"""
4861
Helper method for common parse actions that simply return
4962
a literal value. Especially useful when used with
@@ -60,7 +73,7 @@ def replace_with(repl_str):
6073
return lambda s, l, t: [repl_str]
6174

6275

63-
def remove_quotes(s, l, t):
76+
def remove_quotes(s: str, l: int, t: ParseResults) -> Any:
6477
"""
6578
Helper parse action for removing quotation marks from parsed
6679
quoted strings.
@@ -77,7 +90,7 @@ def remove_quotes(s, l, t):
7790
return t[0][1:-1]
7891

7992

80-
def with_attribute(*args, **attr_dict):
93+
def with_attribute(*args: tuple[str, str], **attr_dict) -> ParseAction:
8194
"""
8295
Helper to create a validating parse action to be used with start
8396
tags created with :class:`make_xml_tags` or
@@ -133,17 +146,17 @@ def with_attribute(*args, **attr_dict):
133146
1 4 0 1 0
134147
1,3 2,3 1,1
135148
"""
149+
attrs_list: list[tuple[str, str]] = []
136150
if args:
137-
attrs = args[:]
151+
attrs_list.extend(args)
138152
else:
139-
attrs = attr_dict.items()
140-
attrs = [(k, v) for k, v in attrs]
153+
attrs_list.extend(attr_dict.items())
141154

142-
def pa(s, l, tokens):
143-
for attrName, attrValue in attrs:
155+
def pa(s: str, l: int, tokens: ParseResults) -> None:
156+
for attrName, attrValue in attrs_list:
144157
if attrName not in tokens:
145158
raise ParseException(s, l, "no matching attribute " + attrName)
146-
if attrValue != with_attribute.ANY_VALUE and tokens[attrName] != attrValue:
159+
if attrValue != with_attribute.ANY_VALUE and tokens[attrName] != attrValue: # type: ignore [attr-defined]
147160
raise ParseException(
148161
s,
149162
l,
@@ -156,7 +169,7 @@ def pa(s, l, tokens):
156169
with_attribute.ANY_VALUE = object() # type: ignore [attr-defined]
157170

158171

159-
def with_class(classname, namespace=""):
172+
def with_class(classname: str, namespace: str = "") -> ParseAction:
160173
"""
161174
Simplified version of :class:`with_attribute` when
162175
matching on a div class - made difficult because ``class`` is

contrib/python/pyparsing/py3/pyparsing/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,14 @@ class pyparsing_common:
210210
"""any numeric expression, returns the corresponding Python type"""
211211

212212
fnumber = (
213-
Regex(r"[+-]?\d+\.?\d*([eE][+-]?\d+)?")
213+
Regex(r"[+-]?\d+\.?\d*(?:[eE][+-]?\d+)?")
214214
.set_name("fnumber")
215215
.set_parse_action(convert_to_float)
216216
)
217217
"""any int or real number, returned as float"""
218218

219219
ieee_float = (
220-
Regex(r"(?i)[+-]?((\d+\.?\d*(e[+-]?\d+)?)|nan|inf(inity)?)")
220+
Regex(r"(?i:[+-]?(?:(?:\d+\.?\d*(?:e[+-]?\d+)?)|nan|inf(?:inity)?))")
221221
.set_name("ieee_float")
222222
.set_parse_action(convert_to_float)
223223
)

contrib/python/pyparsing/py3/pyparsing/core.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,7 @@ def _should_enable_warnings(
215215
_generatorType = types.GeneratorType
216216
ParseImplReturnType = tuple[int, Any]
217217
PostParseReturnType = Union[ParseResults, Sequence[ParseResults]]
218-
ParseAction = Union[
219-
Callable[[], Any],
220-
Callable[[ParseResults], Any],
221-
Callable[[int, ParseResults], Any],
222-
Callable[[str, int, ParseResults], Any],
223-
]
218+
224219
ParseCondition = Union[
225220
Callable[[], bool],
226221
Callable[[ParseResults], bool],
@@ -486,6 +481,7 @@ def __init__(self, savelist: bool = False):
486481
self.callPreparse = True
487482
self.callDuringTry = False
488483
self.suppress_warnings_: list[Diagnostics] = []
484+
self.show_in_diagram = True
489485

490486
def suppress_warning(self, warning_type: Diagnostics) -> ParserElement:
491487
"""
@@ -5558,7 +5554,8 @@ def __or__(self, other) -> ParserElement:
55585554
not in self.suppress_warnings_
55595555
):
55605556
warnings.warn(
5561-
"using '<<' operator with '|' is probably an error, use '<<='",
5557+
"warn_on_match_first_with_lshift_operator:"
5558+
" using '<<' operator with '|' is probably an error, use '<<='",
55625559
stacklevel=2,
55635560
)
55645561
ret = super().__or__(other)
@@ -5572,7 +5569,8 @@ def __del__(self):
55725569
and Diagnostics.warn_on_assignment_to_Forward not in self.suppress_warnings_
55735570
):
55745571
warnings.warn_explicit(
5575-
"Forward defined here but no expression attached later using '<<=' or '<<'",
5572+
"warn_on_assignment_to_Forward:"
5573+
" Forward defined here but no expression attached later using '<<=' or '<<'",
55765574
UserWarning,
55775575
filename=self.caller_frame.filename,
55785576
lineno=self.caller_frame.lineno,
@@ -5600,7 +5598,8 @@ def parseImpl(self, instring, loc, do_actions=True) -> ParseImplReturnType:
56005598
else:
56015599
stacklevel = 2
56025600
warnings.warn(
5603-
"Forward expression was never assigned a value, will not parse any input",
5601+
"warn_on_parse_using_empty_Forward:"
5602+
" Forward expression was never assigned a value, will not parse any input",
56045603
stacklevel=stacklevel,
56055604
)
56065605
if not ParserElement._left_recursion_enabled:
@@ -6157,7 +6156,7 @@ def autoname_elements() -> None:
61576156
Utility to simplify mass-naming of parser elements, for
61586157
generating railroad diagram with named subdiagrams.
61596158
"""
6160-
calling_frame = sys._getframe().f_back
6159+
calling_frame = sys._getframe(1)
61616160
if calling_frame is None:
61626161
return
61636162
calling_frame = typing.cast(types.FrameType, calling_frame)

0 commit comments

Comments
 (0)