as noted in:
>>> import simpleeval
>>> class Foo:
... def __add__(self, other):
... raise Exception('alas!')
...
>>> simpleeval.simple_eval('foo + 21', names={"foo": Foo()})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/daniel/src/simpleeval/simpleeval.py", line 768, in simple_eval
return s.eval(expr)
^^^^^^^^^^^^
File "/Users/daniel/src/simpleeval/simpleeval.py", line 433, in eval
return self._eval(previously_parsed or self.parse(expr))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/daniel/src/simpleeval/simpleeval.py", line 445, in _eval
return handler(node)
^^^^^^^^^^^^^
File "/Users/daniel/src/simpleeval/simpleeval.py", line 448, in _eval_expr
return self._eval(node.value)
^^^^^^^^^^^^^^^^^^^^^^
File "/Users/daniel/src/simpleeval/simpleeval.py", line 445, in _eval
return handler(node)
^^^^^^^^^^^^^
File "/Users/daniel/src/simpleeval/simpleeval.py", line 502, in _eval_binop
return operator(self._eval(node.left), self._eval(node.right))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/daniel/src/simpleeval/simpleeval.py", line 272, in safe_add
return a + b
~~^~~
File "<stdin>", line 3, in __add__
Exception: alas!
so should we have a way to only run the various __add__ etc operators on classes that have been explicitly allowed to?
as noted in:
so should we have a way to only run the various
__add__etc operators on classes that have been explicitly allowed to?