File tree 3 files changed +7
-10
lines changed 3 files changed +7
-10
lines changed Original file line number Diff line number Diff line change @@ -251,8 +251,11 @@ impl SymbolTableAnalyzer {
251
251
if found_in_outer_scope {
252
252
// Symbol is in some outer scope.
253
253
symbol. is_free = true ;
254
+ } else if self . tables . is_empty ( ) {
255
+ // Don't make assumptions when we don't know.
256
+ symbol. scope = SymbolScope :: Unknown ;
254
257
} else {
255
- // Well, it must be a global then :)
258
+ // If there are scopes above we can assume global.
256
259
symbol. scope = SymbolScope :: Global ;
257
260
}
258
261
}
Original file line number Diff line number Diff line change @@ -15,8 +15,11 @@ def b():
15
15
16
16
def x ():
17
17
def y ():
18
+ global a
18
19
nonlocal b
20
+ assert a == 4 , a
19
21
b = 3
22
+ a = "no!" # a here shouldn't be seen by the global above.
20
23
b = 2
21
24
y ()
22
25
return b
Original file line number Diff line number Diff line change @@ -179,15 +179,6 @@ impl NameProtocol for Scope {
179
179
#[ cfg_attr( feature = "flame-it" , flame( "Scope" ) ) ]
180
180
/// Load a global name.
181
181
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.
191
182
if let Some ( value) = self . globals . get_item_option ( name, vm) . unwrap ( ) {
192
183
Some ( value)
193
184
} else {
You can’t perform that action at this time.
0 commit comments