]> granicus.if.org Git - python/commitdiff
Merged revisions 64622 via svnmerge from
authorBenjamin Peterson <benjamin@python.org>
Tue, 1 Jul 2008 20:03:27 +0000 (20:03 +0000)
committerBenjamin Peterson <benjamin@python.org>
Tue, 1 Jul 2008 20:03:27 +0000 (20:03 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r64622 | benjamin.peterson | 2008-07-01 14:34:52 -0500 (Tue, 01 Jul 2008) | 1 line

  #3219 repeated keyword arguments aren't allowed in function calls anymore
........

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

index 11ca4ea88b77614743cd0dcb7377472c13015e35..c82787e548601ef80dc216b6c6204ef0a138025c 100644 (file)
@@ -470,6 +470,12 @@ Make sure that the old "raise X, Y[, Z]" form is gone:
      ...
    SyntaxError: invalid syntax
 
+
+>>> f(a=23, a=234)
+Traceback (most recent call last):
+   ...
+SyntaxError: keyword argument repeated
+
 """
 
 import re
index 79c9403443a46c2b19a0c0f5dc4dd695f0da1eed..6ec2ef1bc6e72f9523ef882a958305d17eecb05f 100644 (file)
@@ -1968,7 +1968,8 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
             }
             else {
                 keyword_ty kw;
-                identifier key;
+                identifier key, tmp;
+                int k;
 
                 /* CHILD(ch, 0) is test, but must be an identifier? */ 
                 e = ast_for_expr(c, CHILD(ch, 0));
@@ -1989,6 +1990,13 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
                  return NULL;
                }
                 key = e->v.Name.id;
+                for (k = 0; k < nkeywords; k++) {
+                    tmp = ((keyword_ty)asdl_seq_GET(keywords, k))->arg;
+                    if (!PyUnicode_Compare(tmp, key)) {
+                        ast_error(CHILD(ch, 0), "keyword argument repeated");
+                        return NULL;
+                    }
+                }
                 e = ast_for_expr(c, CHILD(ch, 2));
                 if (!e)
                     return NULL;