[Python-checkins] r67171 - in python/trunk: Lib/test/test_syntax.py Python/ast.c Python/compile.c
benjamin.peterson
python-checkins at python.org
Sat Nov 8 19:38:55 CET 2008
Author: benjamin.peterson
Date: Sat Nov 8 19:38:54 2008
New Revision: 67171
Log:
check for assignment to __debug__ during AST generation
Also, give assignment to None a better error message
Modified:
python/trunk/Lib/test/test_syntax.py
python/trunk/Python/ast.c
python/trunk/Python/compile.c
Modified: python/trunk/Lib/test/test_syntax.py
==============================================================================
--- python/trunk/Lib/test/test_syntax.py (original)
+++ python/trunk/Lib/test/test_syntax.py Sat Nov 8 19:38:54 2008
@@ -27,15 +27,13 @@
Errors from set_context():
-TODO(jhylton): "assignment to None" is inconsistent with other messages
-
>>> obj.None = 1
Traceback (most recent call last):
-SyntaxError: assignment to None (<doctest test.test_syntax[1]>, line 1)
+SyntaxError: cannot assign to None (<doctest test.test_syntax[1]>, line 1)
>>> None = 1
Traceback (most recent call last):
-SyntaxError: assignment to None (<doctest test.test_syntax[2]>, line 1)
+SyntaxError: cannot assign to None (<doctest test.test_syntax[2]>, line 1)
It's a syntax error to assign to the empty tuple. Why isn't it an
error to assign to the empty list? It will always raise some error at
@@ -95,7 +93,7 @@
>>> def f(None=1):
... pass
Traceback (most recent call last):
-SyntaxError: assignment to None (<doctest test.test_syntax[14]>, line 1)
+SyntaxError: cannot assign to None (<doctest test.test_syntax[14]>, line 1)
From ast_for_arguments():
@@ -108,17 +106,17 @@
>>> def f(x, None):
... pass
Traceback (most recent call last):
-SyntaxError: assignment to None (<doctest test.test_syntax[16]>, line 1)
+SyntaxError: cannot assign to None (<doctest test.test_syntax[16]>, line 1)
>>> def f(*None):
... pass
Traceback (most recent call last):
-SyntaxError: assignment to None (<doctest test.test_syntax[17]>, line 1)
+SyntaxError: cannot assign to None (<doctest test.test_syntax[17]>, line 1)
>>> def f(**None):
... pass
Traceback (most recent call last):
-SyntaxError: assignment to None (<doctest test.test_syntax[18]>, line 1)
+SyntaxError: cannot assign to None (<doctest test.test_syntax[18]>, line 1)
From ast_for_funcdef():
@@ -126,7 +124,7 @@
>>> def None(x):
... pass
Traceback (most recent call last):
-SyntaxError: assignment to None (<doctest test.test_syntax[19]>, line 1)
+SyntaxError: cannot assign to None (<doctest test.test_syntax[19]>, line 1)
From ast_for_call():
@@ -231,7 +229,7 @@
SyntaxError: augmented assignment to generator expression not possible (<doctest test.test_syntax[31]>, line 1)
>>> None += 1
Traceback (most recent call last):
-SyntaxError: assignment to None (<doctest test.test_syntax[32]>, line 1)
+SyntaxError: cannot assign to None (<doctest test.test_syntax[32]>, line 1)
>>> f() += 1
Traceback (most recent call last):
SyntaxError: illegal expression for augmented assignment (<doctest test.test_syntax[33]>, line 1)
Modified: python/trunk/Python/ast.c
==============================================================================
--- python/trunk/Python/ast.c (original)
+++ python/trunk/Python/ast.c Sat Nov 8 19:38:54 2008
@@ -130,7 +130,9 @@
forbidden_check(struct compiling *c, const node *n, const char *x)
{
if (!strcmp(x, "None"))
- return ast_error(n, "assignment to None");
+ return ast_error(n, "cannot assign to None");
+ if (!strcmp(x, "__debug__"))
+ return ast_error(n, "cannot assign to __debug__");
if (Py_Py3kWarningFlag) {
if (!(strcmp(x, "True") && strcmp(x, "False")) &&
!ast_warn(c, n, "assignment to True or False is forbidden in 3.x"))
Modified: python/trunk/Python/compile.c
==============================================================================
--- python/trunk/Python/compile.c (original)
+++ python/trunk/Python/compile.c Sat Nov 8 19:38:54 2008
@@ -2344,12 +2344,6 @@
PyObject *mangled;
/* XXX AugStore isn't used anywhere! */
- /* First check for assignment to __debug__. Param? */
- if ((ctx == Store || ctx == AugStore || ctx == Del)
- && !strcmp(PyString_AS_STRING(name), "__debug__")) {
- return compiler_error(c, "can not assign to __debug__");
- }
-
mangled = _Py_Mangle(c->u->u_private, name);
if (!mangled)
return 0;
More information about the Python-checkins
mailing list