summaryrefslogtreecommitdiff
path: root/pyparsing/helpers.py
diff options
context:
space:
mode:
authorDevin J. Pohly <djpohly@gmail.com>2022-06-17 15:00:11 -0500
committerGitHub <noreply@github.com>2022-06-17 15:00:11 -0500
commit51675ea2b9da964dbfc600a76fa88e1f2e8d988e (patch)
tree023367180fe033ddcc6e25c965884c7515a3edcd /pyparsing/helpers.py
parentcbbbbc9022c179c8d710c7009b0dd587eeb338d4 (diff)
downloadpyparsing-git-51675ea2b9da964dbfc600a76fa88e1f2e8d988e.tar.gz
Explicitly declare compatibility alias functions (#414)
This allows static type checkers to find and check these functions correctly, and it removes the need to fiddle around with stack frames to get the aliases defined.
Diffstat (limited to 'pyparsing/helpers.py')
-rw-r--r--pyparsing/helpers.py52
1 files changed, 39 insertions, 13 deletions
diff --git a/pyparsing/helpers.py b/pyparsing/helpers.py
index 1b48cfc..e4f2b93 100644
--- a/pyparsing/helpers.py
+++ b/pyparsing/helpers.py
@@ -9,14 +9,13 @@ from .util import (
_bslash,
_flatten,
_escape_regex_range_chars,
- replaces_prePEP8_function,
+ replaced_by_pep8,
)
#
# global helpers
#
-@replaces_prePEP8_function("delimitedList")
def delimited_list(
expr: Union[str, ParserElement],
delim: Union[str, ParserElement] = ",",
@@ -72,7 +71,6 @@ def delimited_list(
return delimited_list_expr.set_name(dlName)
-@replaces_prePEP8_function("countedArray")
def counted_array(
expr: ParserElement,
int_expr: typing.Optional[ParserElement] = None,
@@ -133,7 +131,6 @@ def counted_array(
return (intExpr + array_expr).set_name("(len) " + str(expr) + "...")
-@replaces_prePEP8_function("matchPreviousLiteral")
def match_previous_literal(expr: ParserElement) -> ParserElement:
"""Helper to define an expression that is indirectly defined from
the tokens matched in a previous expression, that is, it looks for
@@ -167,7 +164,6 @@ def match_previous_literal(expr: ParserElement) -> ParserElement:
return rep
-@replaces_prePEP8_function("matchPreviousExpr")
def match_previous_expr(expr: ParserElement) -> ParserElement:
"""Helper to define an expression that is indirectly defined from
the tokens matched in a previous expression, that is, it looks for
@@ -204,7 +200,6 @@ def match_previous_expr(expr: ParserElement) -> ParserElement:
return rep
-@replaces_prePEP8_function("oneOf")
def one_of(
strs: Union[typing.Iterable[str], str],
caseless: bool = False,
@@ -330,7 +325,6 @@ def one_of(
)
-@replaces_prePEP8_function("dictOf")
def dict_of(key: ParserElement, value: ParserElement) -> ParserElement:
"""Helper to easily and clearly define a dictionary by specifying
the respective patterns for the key and value. Takes care of
@@ -371,7 +365,6 @@ def dict_of(key: ParserElement, value: ParserElement) -> ParserElement:
return Dict(OneOrMore(Group(key + value)))
-@replaces_prePEP8_function("originalTextFor")
def original_text_for(
expr: ParserElement, as_string: bool = True, *, asString: bool = True
) -> ParserElement:
@@ -467,7 +460,6 @@ def locatedExpr(expr: ParserElement) -> ParserElement:
)
-@replaces_prePEP8_function("nestedExpr")
def nested_expr(
opener: Union[str, ParserElement] = "(",
closer: Union[str, ParserElement] = ")",
@@ -655,7 +647,6 @@ def _makeTags(tagStr, xml, suppress_LT=Suppress("<"), suppress_GT=Suppress(">"))
return openTag, closeTag
-@replaces_prePEP8_function("makeHTMLTags")
def make_html_tags(
tag_str: Union[str, ParserElement]
) -> Tuple[ParserElement, ParserElement]:
@@ -683,7 +674,6 @@ def make_html_tags(
return _makeTags(tag_str, False)
-@replaces_prePEP8_function("makeXMLTags")
def make_xml_tags(
tag_str: Union[str, ParserElement]
) -> Tuple[ParserElement, ParserElement]:
@@ -707,7 +697,6 @@ common_html_entity = Regex("&(?P<entity>" + "|".join(_htmlEntityMap) + ");").set
)
-@replaces_prePEP8_function("replaceHTMLEntity")
def replace_html_entity(s, l, t):
"""Helper parser action to replace common HTML entities with their special characters"""
return _htmlEntityMap.get(t.entity)
@@ -739,7 +728,6 @@ InfixNotationOperatorSpec = Union[
]
-@replaces_prePEP8_function("infixNotation")
def infix_notation(
base_expr: ParserElement,
op_list: List[InfixNotationOperatorSpec],
@@ -1089,6 +1077,7 @@ _builtin_exprs: List[ParserElement] = [
# pre-PEP8 compatible names
+# fmt: off
opAssoc = OpAssoc
anyOpenTag = any_open_tag
anyCloseTag = any_close_tag
@@ -1100,3 +1089,40 @@ dblSlashComment = dbl_slash_comment
cppStyleComment = cpp_style_comment
javaStyleComment = java_style_comment
pythonStyleComment = python_style_comment
+
+@replaced_by_pep8(delimited_list)
+def delimitedList(): ...
+
+@replaced_by_pep8(counted_array)
+def countedArray(): ...
+
+@replaced_by_pep8(match_previous_literal)
+def matchPreviousLiteral(): ...
+
+@replaced_by_pep8(match_previous_expr)
+def matchPreviousExpr(): ...
+
+@replaced_by_pep8(one_of)
+def oneOf(): ...
+
+@replaced_by_pep8(dict_of)
+def dictOf(): ...
+
+@replaced_by_pep8(original_text_for)
+def originalTextFor(): ...
+
+@replaced_by_pep8(nested_expr)
+def nestedExpr(): ...
+
+@replaced_by_pep8(make_html_tags)
+def makeHTMLTags(): ...
+
+@replaced_by_pep8(make_xml_tags)
+def makeXMLTags(): ...
+
+@replaced_by_pep8(replace_html_entity)
+def replaceHTMLEntity(): ...
+
+@replaced_by_pep8(infix_notation)
+def infixNotation(): ...
+# fmt: on