Skip to content

Commit e7ffc9d

Browse files
committed
load_global shouldn't load outermost locals.
1 parent 332c157 commit e7ffc9d

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

tests/snippets/global_nonlocal.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ def b():
1515

1616
def x():
1717
def y():
18+
global a
1819
nonlocal b
20+
assert a == 4, a
1921
b = 3
22+
a = "no!" # a here shouldn't be seen by the global above.
2023
b = 2
2124
y()
2225
return b

vm/src/scope.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,6 @@ impl NameProtocol for Scope {
179179
#[cfg_attr(feature = "flame-it", flame("Scope"))]
180180
/// Load a global name.
181181
fn load_global(&self, vm: &VirtualMachine, name: &str) -> Option<PyObjectRef> {
182-
// First, take a look in the outmost local scope (the scope at top level)
183-
let last_local_dict = self.locals.iter().last();
184-
if let Some(local_dict) = last_local_dict {
185-
if let Some(value) = local_dict.get_item_option(name, vm).unwrap() {
186-
return Some(value);
187-
}
188-
}
189-
190-
// Now, take a look at the globals or builtins.
191182
if let Some(value) = self.globals.get_item_option(name, vm).unwrap() {
192183
Some(value)
193184
} else {

0 commit comments

Comments
 (0)