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

Not All Single Assignments Captured #28

Open
declanvk opened this issue Sep 8, 2018 · 0 comments
Open

Not All Single Assignments Captured #28

declanvk opened this issue Sep 8, 2018 · 0 comments

Comments

@declanvk
Copy link
Collaborator

declanvk commented Sep 8, 2018

The current process for executing code involves a few stages.

  1. The code is converted into an AST
  2. If the last node in the top level is a single assignment, then insert another node after that that evaluates to the assigned variable.
  3. If the last node in the updated, or not updated, top level is an expression of any kind, pull the node off and wrap it in an ast.Interactive.
  4. Wrap everything that remains in an ast.Module.
  5. Execute the ast.Module using exec, and the ast.Interactive using eval.

The Issue

This process will not be able to extract the value of a single assignment if it does not occur last in a code block. For example:

a = 10
print(a)

Will not be able to extract the value of a.

The Solution

Instead of manipulating the AST, it would be better to simply provide the name of the output variable, and then read the variable from the namespace dictionary.

This will eliminate all of the different AST manipulation and the splitting of code into exec and eval, ast.Module and ast.Interactive. All of those steps can be skipped, going straight to execing the block of code.

Sent with GitHawk

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

1 participant