-
-
Notifications
You must be signed in to change notification settings - Fork 170
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
Reassignment of retained vars within one repl invocation causes UnboundLocalError #57
Comments
This is, as remarked, difficult to action upon, because to solve it completely, we'd need a different method of retaining scopes. In terms of things we can do without modifying code, we're unable to unpack into locals, and globals gives us this issue, because there is now a discrepancy between the 'local I don't much like the concept of converting all name lookups - it's not really solving the problem as much as silently inserting behavior that masks it, and it's probably liable to break something elsewhere. The 'safe' way to insert locals would just be to pass extra arguments - this is how stuff like I'm thinking a possible way of getting around this and all other scoping problems is probably just to mess with AST. It could be realistically feasible to either generate arguments using AST, or to pad the beginning of the function with |
Summary
Reassignment of retained variables causes UnboundLocalError
Reproduction steps
jsk retain 1
jsk py x = 1
jsk py x = x + 1
Expected results
x is reassigned to 2.
Actual results
Checklist
System information
Remarks
This is apparently due to x being a global name. Ideally we could pass in locals to the user-defined code, but this is not possible, even with PyCF_ALLOW_TOP_LEVEL_AWAIT. Fixing this might require transforming all name lookups to
globals()['x'] if x in globals() else x
.The text was updated successfully, but these errors were encountered: