]> granicus.if.org Git - python/commitdiff
Disallow function calls like foo(None=1).
authorGeorg Brandl <georg@python.org>
Thu, 7 Jun 2007 13:23:28 +0000 (13:23 +0000)
committerGeorg Brandl <georg@python.org>
Thu, 7 Jun 2007 13:23:28 +0000 (13:23 +0000)
Backport from py3k rev. 55708 by Guido.
 (backport from rev. 55802)

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

index a3f15bf6510c0fef69677987330ad76399a057fc..1a98d2ff9d4deb04c2345cfdaea1f8d860a74d8d 100644 (file)
@@ -37,6 +37,9 @@ class TestSpecifics(unittest.TestCase):
     def test_syntax_error(self):
         self.assertRaises(SyntaxError, compile, "1+*3", "filename", "exec")
 
+    def test_none_keyword_arg(self):
+        self.assertRaises(SyntaxError, compile, "f(None=1)", "<string>", "exec")
+
     def test_duplicate_global_local(self):
         try:
             exec 'def f(a): global a; a = 1'
index 67f45ed0680ab7840897ef4908c16aa04acf69e7..2a27b646984de0593aecccc57a09c6d8c627014b 100644 (file)
@@ -1855,13 +1855,18 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
                  * then is very confusing.
                  */
                 if (e->kind == Lambda_kind) {
-                  ast_error(CHILD(ch, 0), "lambda cannot contain assignment");
-                  return NULL;
+                    ast_error(CHILD(ch, 0),
+                              "lambda cannot contain assignment");
+                    return NULL;
                 } else if (e->kind != Name_kind) {
-                  ast_error(CHILD(ch, 0), "keyword can't be an expression");
-                  return NULL;
+                    ast_error(CHILD(ch, 0), "keyword can't be an expression");
+                    return NULL;
                 }
                key = e->v.Name.id;
+                if (!strcmp(PyString_AS_STRING(key), "None")) {
+                    ast_error(CHILD(ch, 0), "assignment to None");
+                    return NULL;
+                }
                e = ast_for_expr(c, CHILD(ch, 2));
                 if (!e)
                     return NULL;