File: forward_methods.py

package info (click to toggle)
pyparsing 3.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,888 kB
  • sloc: python: 25,293; ansic: 422; makefile: 22
file content (14 lines) | stat: -rw-r--r-- 667 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import pyparsing as pp

# first, some basic validation: forward is a ParserElement, so is Literal
# MatchFirst([Forward(), Literal(...)]) should also be okay
e: pp.ParserElement = pp.Forward()
e = pp.Literal()
e = pp.MatchFirst([pp.Forward(), pp.Literal("hi there")])
# confirm that it isn't returning Any because it cannot be assigned to a str
x: str = pp.Forward() | pp.Literal("oops")  # type: ignore[assignment]

# confirm that `Forward.__or__` has the right behavior
e = pp.Forward() | pp.Literal("nice to meet you")
# and that it isn't returning Any because it cannot be assigned to an int
y: int = pp.Forward() | pp.Literal("oops")  # type: ignore[assignment]