mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
load_global shouldn't load outermost locals.
This commit is contained in:
@@ -15,8 +15,11 @@ assert a == 4
|
||||
|
||||
def x():
|
||||
def y():
|
||||
global a
|
||||
nonlocal b
|
||||
assert a == 4, a
|
||||
b = 3
|
||||
a = "no!" # a here shouldn't be seen by the global above.
|
||||
b = 2
|
||||
y()
|
||||
return b
|
||||
|
||||
@@ -179,15 +179,6 @@ impl NameProtocol for Scope {
|
||||
#[cfg_attr(feature = "flame-it", flame("Scope"))]
|
||||
/// Load a global name.
|
||||
fn load_global(&self, vm: &VirtualMachine, name: &str) -> Option<PyObjectRef> {
|
||||
// First, take a look in the outmost local scope (the scope at top level)
|
||||
let last_local_dict = self.locals.iter().last();
|
||||
if let Some(local_dict) = last_local_dict {
|
||||
if let Some(value) = local_dict.get_item_option(name, vm).unwrap() {
|
||||
return Some(value);
|
||||
}
|
||||
}
|
||||
|
||||
// Now, take a look at the globals or builtins.
|
||||
if let Some(value) = self.globals.get_item_option(name, vm).unwrap() {
|
||||
Some(value)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user