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

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

index d1b6d8cefbac8c5c66159f880235e651008cdf5b..367a6945188da05d7131b09ded6e15650953047f 100644 (file)
@@ -36,6 +36,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 27c3efaac87327a61e56722b8ed89d796443baa2..42dcc2d82646410466204e573f9e84d25f8cf2a7 100644 (file)
@@ -1869,6 +1869,10 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
                     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;