summaryrefslogtreecommitdiff
path: root/pyparsing/helpers.py
diff options
context:
space:
mode:
authorptmcg <ptmcg@austin.rr.com>2022-05-29 20:29:44 -0500
committerptmcg <ptmcg@austin.rr.com>2022-05-29 20:29:44 -0500
commitd570869a9ba683c021545e53bb1ba159bee7c2af (patch)
tree98151f48d3a69e3b4bcf6ccaaf570a1b7e33d206 /pyparsing/helpers.py
parentbd7fd3c112edd9e2741d195154d4d82df986dbad (diff)
downloadpyparsing-git-d570869a9ba683c021545e53bb1ba159bee7c2af.tar.gz
More added type annotations; reworked Word.__init__ so that excludeChars exclusion code is clearer
Diffstat (limited to 'pyparsing/helpers.py')
-rw-r--r--pyparsing/helpers.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/pyparsing/helpers.py b/pyparsing/helpers.py
index 9588b3b..c1de43e 100644
--- a/pyparsing/helpers.py
+++ b/pyparsing/helpers.py
@@ -39,6 +39,7 @@ def delimited_list(
"""
if isinstance(expr, str_type):
expr = ParserElement._literalStringClass(expr)
+ expr = typing.cast(ParserElement, expr)
dlName = "{expr} [{delim} {expr}]...{end}".format(
expr=str(expr.copy().streamline()),
@@ -57,7 +58,7 @@ def delimited_list(
if min is not None and max <= min:
raise ValueError("max must be greater than, or equal to min")
max -= 1
- delimited_list_expr = expr + (delim + expr)[min, max]
+ delimited_list_expr: ParserElement = expr + (delim + expr)[min, max]
if allow_trailing_delim:
delimited_list_expr += Opt(delim)
@@ -823,10 +824,16 @@ def infix_notation(
else:
lastExpr = base_expr | (lpar + ret + rpar)
+ arity: int
+ rightLeftAssoc: opAssoc
+ pa: typing.Optional[ParseAction]
+ opExpr1: ParserElement
+ opExpr2: ParserElement
for i, operDef in enumerate(op_list):
- opExpr, arity, rightLeftAssoc, pa = (operDef + (None,))[:4]
+ opExpr, arity, rightLeftAssoc, pa = (operDef + (None,))[:4] # type: ignore[assignment]
if isinstance(opExpr, str_type):
opExpr = ParserElement._literalStringClass(opExpr)
+ opExpr = typing.cast(ParserElement, opExpr)
if arity == 3:
if not isinstance(opExpr, (tuple, list)) or len(opExpr) != 2:
raise ValueError(
@@ -843,7 +850,8 @@ def infix_notation(
if rightLeftAssoc not in (OpAssoc.LEFT, OpAssoc.RIGHT):
raise ValueError("operator must indicate right or left associativity")
- thisExpr: Forward = Forward().set_name(term_name)
+ thisExpr: ParserElement = Forward().set_name(term_name)
+ thisExpr = typing.cast(Forward, thisExpr)
if rightLeftAssoc is OpAssoc.LEFT:
if arity == 1:
matchExpr = _FB(lastExpr + opExpr) + Group(lastExpr + opExpr[1, ...])