Skip to content

Commit

Permalink
Small perf optimization for expr | "" mapping to Optional(expr)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptmcg committed Mar 29, 2023
1 parent 14067a9 commit 05d894d
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pyparsing/core.py
Expand Up @@ -1552,6 +1552,9 @@ def __or__(self, other) -> "ParserElement":
return _PendingSkip(self, must_skip=True)

if isinstance(other, str_type):
# `expr | ""` is equivalent to `Opt(expr)`
if other == "":
return Opt(self)
other = self._literalStringClass(other)
if not isinstance(other, ParserElement):
return NotImplemented
Expand Down

0 comments on commit 05d894d

Please sign in to comment.