]> granicus.if.org Git - python/commitdiff
move test_trace.py so as not to conflict with future tests for the trace module
authorBenjamin Peterson <benjamin@python.org>
Tue, 20 Jul 2010 22:37:19 +0000 (22:37 +0000)
committerBenjamin Peterson <benjamin@python.org>
Tue, 20 Jul 2010 22:37:19 +0000 (22:37 +0000)
Include/opcode.h
Include/symtable.h
Lib/test/test_line_tracing.py [moved from Lib/test/test_trace.py with 100% similarity]
Lib/test/test_scope.py
Objects/typeobject.c
Python/ceval.c
Python/compile.c
Python/symtable.c

index 7ffa359bca09e39de79b604e486e6bc7de24f775..facadc2c778ba28fbc6536e7c868a0d1836bbd7f 100644 (file)
@@ -123,6 +123,7 @@ extern "C" {
 #define LOAD_CLOSURE    135     /* Load free variable from closure */
 #define LOAD_DEREF      136     /* Load and dereference from closure cell */ 
 #define STORE_DEREF     137     /* Store into cell */ 
+#define LOAD_NAME_LOCAL_ONLY 138
 
 /* The next 3 opcodes must be contiguous and satisfy
    (CALL_FUNCTION_VAR - CALL_FUNCTION) & 3 == 1  */
index d5ef96f80210d28e2d6c0333a58e98316e0d6fb2..22075f011dea93d265b72a7bb516fa64808d76fc 100644 (file)
@@ -88,6 +88,7 @@ PyAPI_FUNC(void) PySymtable_Free(struct symtable *);
 #define GLOBAL_IMPLICIT 3
 #define FREE 4
 #define CELL 5
+#define LOCAL_ONLY 6
 
 /* The following two names are used for the ste_unoptimized bit field */
 #define OPT_IMPORT_STAR 1
index 643dcbc6d55c6c3c406d0290e00a480ec6f0b678..1961e6edf2d248e1e2e309fcc7a070a8d64fc1ae 100644 (file)
@@ -690,6 +690,14 @@ result2 = h()
         h = g()
         self.assertEqual(h(), 3)
 
+    def testLocalClosureShadowing(self):
+        exec("""
+x = 4
+def f(x):
+    class C:
+         x = x
+raises(NameError, f, 3)""", {"raises" : self.assertRaises})
+
 
 def test_main():
     run_unittest(ScopeTests)
index 268a9244bbf37a566f9cc5ac74a5ae4b3fa076bd..505ca68c2fecf3254b3db763a49a8205fd45e376 100644 (file)
@@ -6094,6 +6094,7 @@ supercheck(PyTypeObject *type, PyObject *obj)
     PyErr_SetString(PyExc_TypeError,
                     "super(type, obj): "
                     "obj must be an instance or subtype of type");
+    printf("%s\n", type->tp_name);
     return NULL;
 }
 
index 2d4b16a39a2726ac49b49f6a761091f457029861..368ad695ea4a29a56e6c110012a381a6004d21a4 100644 (file)
@@ -2052,6 +2052,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
             break;
 
         TARGET(LOAD_NAME)
+        TARGET(LOAD_NAME_LOCAL_ONLY)
             w = GETITEM(names, oparg);
             if ((v = f->f_locals) == NULL) {
                 PyErr_Format(PyExc_SystemError,
@@ -2073,15 +2074,14 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
                 }
             }
             if (x == NULL) {
-                x = PyDict_GetItem(f->f_globals, w);
+                if (opcode != LOAD_NAME_LOCAL_ONLY) {
+                    x = PyDict_GetItem(f->f_globals, w);
+                    if (x == NULL)
+                        x = PyDict_GetItem(f->f_builtins, w);
+                }
                 if (x == NULL) {
-                    x = PyDict_GetItem(f->f_builtins, w);
-                    if (x == NULL) {
-                        format_exc_check_arg(
-                                    PyExc_NameError,
-                                    NAME_ERROR_MSG, w);
-                        break;
-                    }
+                    format_exc_check_arg(PyExc_NameError, NAME_ERROR_MSG, w);
+                    break;
                 }
                 Py_INCREF(x);
             }
index aae0339c2cf6343504ea4f74e27c3f90992b8acc..83c9e0211ed8fcf0372363a5d2dc504e18d57a1e 100644 (file)
@@ -787,6 +787,7 @@ opcode_stack_effect(int opcode, int oparg)
         case LOAD_CONST:
             return 1;
         case LOAD_NAME:
+        case LOAD_NAME_LOCAL_ONLY:
             return 1;
         case BUILD_TUPLE:
         case BUILD_LIST:
@@ -2481,6 +2482,7 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
         optype = OP_DEREF;
         break;
     case LOCAL:
+    case LOCAL_ONLY:
         if (c->u->u_ste->ste_type == FunctionBlock)
             optype = OP_FAST;
         break;
@@ -2556,7 +2558,7 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
         break;
     case OP_NAME:
         switch (ctx) {
-        case Load: op = LOAD_NAME; break;
+        case Load: op = (scope == LOCAL_ONLY) ? LOAD_NAME_LOCAL_ONLY : LOAD_NAME; break;
         case Store: op = STORE_NAME; break;
         case Del: op = DELETE_NAME; break;
         case AugLoad:
index 55c9f472fcc793f894f3ff774f5ac3780b757c77..37bdf2a1051a4727b8fcf586267808f8e0fdf6fd 100644 (file)
@@ -432,7 +432,14 @@ analyze_name(PySTEntryObject *ste, PyObject *scopes, PyObject *name, long flags,
         return PySet_Add(free, name) >= 0;
     }
     if (flags & DEF_BOUND) {
-        SET_SCOPE(scopes, name, LOCAL);
+        if (ste->ste_type == ClassBlock &&
+            !(flags & DEF_PARAM) &&
+            bound && PySet_Contains(bound, name)) {
+            SET_SCOPE(scopes, name, LOCAL_ONLY);
+        }
+        else {
+            SET_SCOPE(scopes, name, LOCAL);
+        }
         if (PySet_Add(local, name) < 0)
             return 0;
         if (PySet_Discard(global, name) < 0)
@@ -489,7 +496,7 @@ analyze_cells(PyObject *scopes, PyObject *free, const char *restricted)
         long scope;
         assert(PyLong_Check(v));
         scope = PyLong_AS_LONG(v);
-        if (scope != LOCAL)
+        if (scope != LOCAL && scope != LOCAL_ONLY)
             continue;
         if (!PySet_Contains(free, name))
             continue;