Skip to content

Commit

Permalink
use try/except for comparison short-circuiting instead of checking fo…
Browse files Browse the repository at this point in the history
…r numpy arrays (adressing GH 123)
  • Loading branch information
newville committed Nov 6, 2023
1 parent 7990a85 commit 3806cde
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions asteval/asteval.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,15 +670,18 @@ def on_compare(self, node): # ('left', 'ops', 'comparators')
rval = self.run(rnode)
ret = op2func(oper)(lval, rval)
results.append(ret)
if ((self.use_numpy and not isinstance(ret, numpy.ndarray)) and
not ret):
break
try:
if not ret:
break
except ValueError:
pass
lval = rval
if len(results) == 1:
return results[0]
out = True
for ret in results:
out = out and ret
out = results[0]
else:
out = True
for ret in results:
out = out and ret
return out

def _printer(self, *out, **kws):
Expand Down

0 comments on commit 3806cde

Please sign in to comment.