asteval icon indicating copy to clipboard operation
asteval copied to clipboard

hiding errors prints

Open xhajnal opened this issue 5 years ago • 1 comments

Could you introduce a switch to turn prints of errors off?

it seems as it is asteval.py lines 324, 328: print(errmsg, file=self.err_writer)

Thank you.

xhajnal avatar Mar 28 '21 12:03 xhajnal

@xhajnal One can set the err_writer attribute, or pass it in on creating the interpreter:

   aeval = Interpreter(err_writer=open('/dev/null', 'w'))

for example. I think your app could also replace sys.stderr before creating the Interpreter.

Looking at this again, I think the logic of eval() should be changed to (in part to stay back-compatible) to use show_errors to print error messages (one could still explicitly set the err_writer attribute), and raise_errors to raise the error in the calling code. With that change,

eval(expression, show_errors=False, raise_errors=False) would be silent on errors. Can't say I would recommend using that, but separating raise from show seems reasonable.

newville avatar Mar 28 '21 13:03 newville