Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange behaviour when asteval throws an exception #63

Closed
bek0s opened this issue Nov 12, 2019 · 2 comments
Closed

Strange behaviour when asteval throws an exception #63

bek0s opened this issue Nov 12, 2019 · 2 comments

Comments

@bek0s
Copy link

bek0s commented Nov 12, 2019

Hello,

I have the following code:

import asteval
expreval = asteval.Interpreter(minimal=True, use_numpy=False)
expreval("a=sin('1')")
for error in expreval.error:
    print(error.get_error())

When I run it, it produces the following output:

TypeError
   a=sin('1')
      ^^^
Error running function call 'sin' with args ['1'] and kwargs {}: must be real number, not str
('TypeError', "   a=sin('1')\n      ^^^\nError running function call 'sin' with args ['1'] and kwargs {}: must be real number, not str")
('TypeError', "   a=sin('1')\n      ^^^\nat expr='a=sin('1')'")
('TypeError', "   a=sin('1')\nat expr='a=sin('1')'")
('TypeError', "   a=sin('1')\nat expr='a=sin('1')'")

I am a bit confused as to why the code results in 4 errors instead of one. To me, it seems that only expreval.error[0] should be generated. Is this a bug or a feature? Or maybe I am missing something?

Thank you

PS: I am using Python 3.7

@bek0s bek0s changed the title Strange behaviour when asteval throws and exception Strange behaviour when asteval throws an exception Nov 12, 2019
@chrisjbremner
Copy link
Contributor

Hi @bek0s, this should be resolved by https://github.com/newville/asteval/pull/64. Hopefully @newville will cut a new release soon so you can update the package using pip. @newville it looks like you need to close this issue too, since I don't have the ability to do so.

@newville
Copy link
Member

@bek0s @chrisjbremner OK, closing, and I will push a new release within a day or two...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants