summaryrefslogtreecommitdiff
path: root/pyparsing
diff options
context:
space:
mode:
authorptmcg <ptmcg@austin.rr.com>2022-07-04 20:06:13 -0500
committerptmcg <ptmcg@austin.rr.com>2022-07-04 20:06:13 -0500
commit05b3aad6bccdb4d82147077c1b530b09455d8ab8 (patch)
treeb9096d9ce04afea8fdae2820b2f5ff40d4fa63fa /pyparsing
parentd8af08511bbfd9e441ac6910c96afd3a3ebf2a34 (diff)
downloadpyparsing-git-05b3aad6bccdb4d82147077c1b530b09455d8ab8.tar.gz
Add return of NotImplemented to other binary operators (similar to PR #425), and add unit tests
Diffstat (limited to 'pyparsing')
-rw-r--r--pyparsing/__init__.py2
-rw-r--r--pyparsing/core.py20
2 files changed, 21 insertions, 1 deletions
diff --git a/pyparsing/__init__.py b/pyparsing/__init__.py
index 7970791..ffe89d0 100644
--- a/pyparsing/__init__.py
+++ b/pyparsing/__init__.py
@@ -121,7 +121,7 @@ class version_info(NamedTuple):
__version_info__ = version_info(3, 0, 10, "final", 0)
-__version_time__ = "29 Jun 2022 06:57 UTC"
+__version_time__ = "05 Jul 2022 01:03 UTC"
__version__ = __version_info__.__version__
__versionTime__ = __version_time__
__author__ = "Paul McGuire <ptmcg.gm+pyparsing@gmail.com>"
diff --git a/pyparsing/core.py b/pyparsing/core.py
index fd5889a..54846f5 100644
--- a/pyparsing/core.py
+++ b/pyparsing/core.py
@@ -3940,6 +3940,8 @@ class And(ParseExpression):
def __iadd__(self, other):
if isinstance(other, str_type):
other = self._literalStringClass(other)
+ if not isinstance(other, ParserElement):
+ return NotImplemented
return self.append(other) # And([self, other])
def _checkRecursion(self, parseElementList):
@@ -4080,6 +4082,8 @@ class Or(ParseExpression):
def __ixor__(self, other):
if isinstance(other, str_type):
other = self._literalStringClass(other)
+ if not isinstance(other, ParserElement):
+ return NotImplemented
return self.append(other) # Or([self, other])
def _generateDefaultName(self) -> str:
@@ -4191,6 +4195,8 @@ class MatchFirst(ParseExpression):
def __ior__(self, other):
if isinstance(other, str_type):
other = self._literalStringClass(other)
+ if not isinstance(other, ParserElement):
+ return NotImplemented
return self.append(other) # MatchFirst([self, other])
def _generateDefaultName(self) -> str:
@@ -4291,6 +4297,13 @@ class Each(ParseExpression):
self.initExprGroups = True
self.saveAsList = True
+ def __iand__(self, other):
+ if isinstance(other, str_type):
+ other = self._literalStringClass(other)
+ if not isinstance(other, ParserElement):
+ return NotImplemented
+ return self.append(other) # Each([self, other])
+
def streamline(self) -> ParserElement:
super().streamline()
if self.exprs:
@@ -5216,6 +5229,10 @@ class Forward(ParseElementEnhance):
del self.caller_frame
if isinstance(other, str_type):
other = self._literalStringClass(other)
+
+ if not isinstance(other, ParserElement):
+ return NotImplemented
+
self.expr = other
self.mayIndexError = self.expr.mayIndexError
self.mayReturnEmpty = self.expr.mayReturnEmpty
@@ -5229,6 +5246,9 @@ class Forward(ParseElementEnhance):
return self
def __ilshift__(self, other) -> "Forward":
+ if not isinstance(other, ParserElement):
+ return NotImplemented
+
return self << other
def __or__(self, other) -> "ParserElement":