-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Proper construction of scope for exec/eval. #590
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #590 +/- ##
==========================================
+ Coverage 41.61% 43.75% +2.14%
==========================================
Files 74 74
Lines 16762 17228 +466
Branches 4406 4671 +265
==========================================
+ Hits 6975 7538 +563
+ Misses 7781 7594 -187
- Partials 2006 2096 +90
Continue to review full report at Codecov.
|
Looks like CPython doesn't do "automatic" dict type checking there, and just allows any type, then checks for None, then manually typechecks for dict. |
In that case I've added a macro to do the extra checking. This leads me to run into the limitations of our definitions of scope. We consider local scope to be the nearest scope to us so top level statements execute with local and global scope being the same thing. In python though this means there is no local scope, creating one doesn't replace the current local==global scope. This should work, but doesn't:
We'll need to sort this out to implement the |
Uh... the above is wrong. It looks like creating a new local scope never replaces the existing local scope. (Ie. that code still works even in a function.) This is all wrong. :( |
I was right the first time! :) |
Interesting example:
|
locals: Option<&PyObjectRef>, | ||
) -> ScopeRef { | ||
let current_scope = vm.current_scope(); | ||
let parent = match globals { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check here if globals is passed at all, None or an actual dictionary.
One case I couldn't handle is that the following is valid in CPython.
arg_check!
needs to allow None and treat it as if the optional argument wasn't passed. I don't know what other builtins have this behaviour.