Fix arigo's funky LOAD_NAME bug: implicit globals inside classes have
historically been looked up using LOAD_NAME, not LOAD_GLOBAL.
looked up by LOAD_NAME, not
diff --git a/Lib/test/test_scope.py b/Lib/test/test_scope.py
index 34801bd..f37254c 100644
--- a/Lib/test/test_scope.py
+++ b/Lib/test/test_scope.py
@@ -440,6 +440,15 @@
x = -1
vereq(test(3)(2), 5)
+looked_up_by_load_name = False
+class X:
+ # Implicit globals inside classes are be looked up by LOAD_NAME, not
+ # LOAD_GLOBAL.
+ locals()['looked_up_by_load_name'] = True
+ passed = looked_up_by_load_name
+
+verify(X.passed)
+
print "18. verify that locals() works"
def f(x):
diff --git a/Python/compile.c b/Python/compile.c
index 93cfb64..61e22d1 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -2731,7 +2731,8 @@
optype = OP_FAST;
break;
case GLOBAL_IMPLICIT:
- if (!c->u->u_ste->ste_unoptimized)
+ if (c->u->u_ste->ste_type == FunctionBlock &&
+ !c->u->u_ste->ste_unoptimized)
optype = OP_GLOBAL;
break;
case GLOBAL_EXPLICIT: