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

Exception handlers don't correctly assign to the symbol table #137

Closed
W-M-T opened this issue Jan 14, 2025 · 1 comment · Fixed by #138
Closed

Exception handlers don't correctly assign to the symbol table #137

W-M-T opened this issue Jan 14, 2025 · 1 comment · Fixed by #138

Comments

@W-M-T
Copy link

W-M-T commented Jan 14, 2025

This code snippet reproduces the problem:

import asteval
asteval.Interpreter().eval("""
try:
    2 + ""
except Exception as err:
    print(err)
""", raise_errors=True)

OUTPUT:

NameError:    
try:
    2 + ""
except Exception as err:
    print(err)

              ^^^^
NameError: name 'err' is not defined

What's going wrong here:
From the documentation of ast.ExceptHandler:
name is a raw string for the name to hold the exception, or None if the clause doesn’t have as

In on_try, at this line

self.node_assign(hnd.name, e_value)

node_assign is called with the hnd.name which is a string.
However, node_assign does not have a case for str so the exception is never assigned to a name in the symbol table.

@newville
Copy link
Member

@W-M-T Thanks -- I will have a quick fix shortly, and hope to get 1.0.6 out in a day or so.

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

Successfully merging a pull request may close this issue.

2 participants