[Python-3000-checkins] r59443 - in python/branches/py3k: Lib/test/test_ast.py Lib/test/test_keywordonlyarg.py Python/ast.c

amaury.forgeotdarc python-3000-checkins at python.org
Sun Dec 9 22:49:48 CET 2007


Author: amaury.forgeotdarc
Date: Sun Dec  9 22:49:48 2007
New Revision: 59443

Modified:
   python/branches/py3k/Lib/test/test_ast.py
   python/branches/py3k/Lib/test/test_keywordonlyarg.py
   python/branches/py3k/Python/ast.c
Log:
Issue #1573, second attempt:
"def f(*, **kw)" now raises a SyntaxError.


Modified: python/branches/py3k/Lib/test/test_ast.py
==============================================================================
--- python/branches/py3k/Lib/test/test_ast.py	(original)
+++ python/branches/py3k/Lib/test/test_ast.py	Sun Dec  9 22:49:48 2007
@@ -58,9 +58,6 @@
     "break",
     # Continue
     "continue",
-    # kw only funcs
-    "def f(*, kw=1): pass",
-    "def f(*, **kw): pass",
 ]
 
 # These are compiled through "single"

Modified: python/branches/py3k/Lib/test/test_keywordonlyarg.py
==============================================================================
--- python/branches/py3k/Lib/test/test_keywordonlyarg.py	(original)
+++ python/branches/py3k/Lib/test/test_keywordonlyarg.py	Sun Dec  9 22:49:48 2007
@@ -48,6 +48,7 @@
         self.assertRaisesSyntaxError("def f(p1, *, p1=100):\n  pass\n")
         self.assertRaisesSyntaxError("def f(p1, *k1, k1=100):\n  pass\n")
         self.assertRaisesSyntaxError("def f(p1, *, k1, k1=100):\n  pass\n")
+        self.assertRaisesSyntaxError("def f(p1, *, **k1):\n  pass\n")
         self.assertRaisesSyntaxError("def f(p1, *, k1, **k1):\n  pass\n")
         self.assertRaisesSyntaxError("def f(p1, *, None, **k1):\n  pass\n")
         self.assertRaisesSyntaxError("def f(p, *, (k1, k2), **kw):\n  pass\n")
@@ -144,13 +145,6 @@
         except TypeError:
             pass
 
-    def test_doublestar_only(self):
-        def f(*, **kw):
-            return kw
-
-        self.assertEqual(f(), {})
-        self.assertEqual(f(k1=1, k2=2), {'k1' : 1, 'k2' : 2})
-
     def test_kwonly_methods(self):
         class Example:
             def f(self, *, k1=1, k2=2):

Modified: python/branches/py3k/Python/ast.c
==============================================================================
--- python/branches/py3k/Python/ast.c	(original)
+++ python/branches/py3k/Python/ast.c	Sun Dec  9 22:49:48 2007
@@ -649,8 +649,12 @@
     arg_ty arg;
     int i = start;
     int j = 0; /* index for kwdefaults and kwonlyargs */
-    assert((kwonlyargs != NULL && kwdefaults != NULL) ||
-           TYPE(CHILD(n, i)) == DOUBLESTAR);
+
+    if (kwonlyargs == NULL) {
+        ast_error(CHILD(n, start), "named arguments must follow bare *");
+        return -1;
+    }
+    assert(kwdefaults != NULL);
     while (i < NCH(n)) {
         ch = CHILD(n, i);
         switch (TYPE(ch)) {
@@ -814,7 +818,8 @@
                 break;
             case STAR:
                 if (i+1 >= NCH(n)) {
-                    ast_error(CHILD(n, i), "no name for vararg");
+                    ast_error(CHILD(n, i), 
+                        "named arguments must follow bare *");
                     goto error;
                 }
                 ch = CHILD(n, i+1);  /* tfpdef or COMMA */


More information about the Python-3000-checkins mailing list