[Python-checkins] r55802 - in python/trunk: Lib/test/test_compile.py Python/ast.c

georg.brandl python-checkins at python.org
Thu Jun 7 15:23:25 CEST 2007


Author: georg.brandl
Date: Thu Jun  7 15:23:24 2007
New Revision: 55802

Modified:
   python/trunk/Lib/test/test_compile.py
   python/trunk/Python/ast.c
Log:
Disallow function calls like foo(None=1).
Backport from py3k rev. 55708 by Guido.


Modified: python/trunk/Lib/test/test_compile.py
==============================================================================
--- python/trunk/Lib/test/test_compile.py	(original)
+++ python/trunk/Lib/test/test_compile.py	Thu Jun  7 15:23:24 2007
@@ -36,6 +36,9 @@
     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'

Modified: python/trunk/Python/ast.c
==============================================================================
--- python/trunk/Python/ast.c	(original)
+++ python/trunk/Python/ast.c	Thu Jun  7 15:23:24 2007
@@ -1869,6 +1869,10 @@
                     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;


More information about the Python-checkins mailing list