]> granicus.if.org Git - python/commitdiff
Fix arigo's funky LOAD_NAME bug: implicit globals inside classes have
authorNeil Schemenauer <nascheme@enme.ucalgary.ca>
Sun, 23 Oct 2005 04:24:49 +0000 (04:24 +0000)
committerNeil Schemenauer <nascheme@enme.ucalgary.ca>
Sun, 23 Oct 2005 04:24:49 +0000 (04:24 +0000)
historically been looked up using LOAD_NAME, not LOAD_GLOBAL.
looked up by LOAD_NAME, not

Lib/test/test_scope.py
Python/compile.c

index 34801bd1638c20b55b127fe6898af19400b87ccc..f37254c9df9533a29a35ae8310b2ebaf794a8011 100644 (file)
@@ -440,6 +440,15 @@ vereq(test(6)(2), 8)
 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):
index 93cfb641e0d033bd566136740ec25eee21a5a388..61e22d10fe077f11cfbfefa9a3b4e932165bd7b8 100644 (file)
@@ -2731,7 +2731,8 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
                        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: