summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-07-17 21:46:25 +0000
committerRaymond Hettinger <python@rcn.com>2004-07-17 21:46:25 +0000
commit4db4b91788ca58113b7feb413773b9432777242e (patch)
treefa785eb1d8b6c977d534fb82396b31d69ad0b30f
parent8e6ab02b82175a47632f1dcffd830abec35c46f3 (diff)
downloadcpython-4db4b91788ca58113b7feb413773b9432777242e.tar.gz
Upgrade None assignment SyntaxWarning to a SyntaxError.
-rw-r--r--Lib/test/test_compile.py15
-rw-r--r--Python/compile.c13
2 files changed, 21 insertions, 7 deletions
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index e2b1c9500d..5b7b7170df 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -138,6 +138,21 @@ if 1:
self.assertEqual(i, 1)
self.assertEqual(j, -1)
+ def test_none_assignment(self):
+ stmts = [
+ 'None = 0',
+ 'None += 0',
+ '__builtins__.None = 0',
+ 'def None(): pass',
+ 'class None: pass',
+ '(a, None) = 0, 0',
+ 'for None in range(10): pass',
+ 'def f(None): pass',
+ ]
+ for stmt in stmts:
+ stmt += "\n"
+ self.assertRaises(SyntaxError, compile, stmt, 'tmp', 'single')
+ self.assertRaises(SyntaxError, compile, stmt, 'tmp', 'exec')
def test_main():
test_support.run_unittest(TestSpecifics)
diff --git a/Python/compile.c b/Python/compile.c
index 5549e9f75b..771bc2fa8a 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1227,10 +1227,8 @@ none_assignment_check(struct compiling *c, char *name, int assigning)
msg = "assignment to None";
else
msg = "deleting None";
- if (issue_warning(msg, c->c_filename, c->c_lineno) < 0) {
- c->c_errors++;
- return -1;
- }
+ com_error(c, PyExc_SyntaxError, msg);
+ return -1;
}
return 0;
}
@@ -1247,7 +1245,6 @@ com_addop_varname(struct compiling *c, int kind, char *name)
if (kind != VAR_LOAD &&
none_assignment_check(c, name, kind == VAR_STORE))
{
- c->c_errors++;
i = 255;
goto done;
}
@@ -5483,8 +5480,10 @@ symtable_add_def(struct symtable *st, char *name, int flag)
if ((flag & DEF_PARAM) && !(flag & DEF_INTUPLE) &&
*name == 'N' && strcmp(name, "None") == 0)
{
- if (symtable_warn(st, "argument named None"))
- return -1;
+ PyErr_SetString(PyExc_SyntaxError,
+ "Invalid syntax. Assignment to None.");
+ symtable_error(st, 0);
+ return -1;
}
if (_Py_Mangle(st->st_private, name, buffer, sizeof(buffer)))
name = buffer;