diff options
-rw-r--r-- | Lib/test/test_compile.py | 14 | ||||
-rw-r--r-- | Python/compile.c | 9 |
2 files changed, 20 insertions, 3 deletions
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index 9f20ba1..e976a30 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -1,6 +1,17 @@ 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' try: @@ -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 diff --git a/Python/compile.c b/Python/compile.c index c8a5669..1a46064 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -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; |