]> granicus.if.org Git - python/commitdiff
Fix SF buf #480096: Assign to __debug__ still allowed
authorJeremy Hylton <jeremy@alum.mit.edu>
Fri, 9 Nov 2001 19:50:08 +0000 (19:50 +0000)
committerJeremy Hylton <jeremy@alum.mit.edu>
Fri, 9 Nov 2001 19:50:08 +0000 (19:50 +0000)
Easy enough to catch assignment in the compiler.  The perverse user
can still change the value of __debug__, but that may be the least he
can do.

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

index 9f20ba1377d798e8ed9e8e515b1924a4833fa0a4..e976a30dd5ff88af209a05ac9ddfb21381f44658 100644 (file)
@@ -1,5 +1,16 @@
 from test_support import verbose, TestFailed
 
+if verbose:
+    print "Testing whether compiler catches assignment to __debug__"
+
+try:
+    compile('__debug__ = 1', '?', 'single')
+except SyntaxError:
+    pass
+
+import __builtin__
+setattr(__builtin__, '__debug__', 'sure')
+
 if verbose:
     print 'Running tests on argument handling'
 
@@ -21,7 +32,8 @@ try:
 except SyntaxError:
     pass
 
-print "testing complex args"
+if verbose:
+    print "testing complex args"
 
 def comp_args((a, b)):
     print a,b
index c8a56699bc1f11b55852369d1a0f7425a2bd88d4..1a46064dd47b6549ba2d04c86557eb8e747bc58b 100644 (file)
@@ -5459,8 +5459,13 @@ symtable_assign(struct symtable *st, node *n, int def_flag)
                        n = CHILD(n, 1);
                        goto loop;
                } else if (TYPE(tmp) == NAME) {
-                       if (strcmp(STR(tmp), "__debug__") == 0)
-                               symtable_warn(st, ASSIGN_DEBUG);
+                       if (strcmp(STR(tmp), "__debug__") == 0) {
+                               PyErr_SetString(PyExc_SyntaxError, 
+                                               ASSIGN_DEBUG);
+                               PyErr_SyntaxLocation(st->st_filename,
+                                            st->st_cur->ste_opt_lineno);
+                               st->st_errors++;
+                       }
                        symtable_add_def(st, STR(tmp), DEF_LOCAL | def_flag);
                }
                return;