Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 07a1f94

Browse files
committed
Merged revisions 64622 via svnmerge from
svn+ssh://[email protected]/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 ........
1 parent 13e8946 commit 07a1f94

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

Lib/test/test_syntax.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,12 @@
470470
...
471471
SyntaxError: invalid syntax
472472
473+
474+
>>> f(a=23, a=234)
475+
Traceback (most recent call last):
476+
...
477+
SyntaxError: keyword argument repeated
478+
473479
"""
474480

475481
import re

Python/ast.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1968,7 +1968,8 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
19681968
}
19691969
else {
19701970
keyword_ty kw;
1971-
identifier key;
1971+
identifier key, tmp;
1972+
int k;
19721973

19731974
/* CHILD(ch, 0) is test, but must be an identifier? */
19741975
e = ast_for_expr(c, CHILD(ch, 0));
@@ -1989,6 +1990,13 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
19891990
return NULL;
19901991
}
19911992
key = e->v.Name.id;
1993+
for (k = 0; k < nkeywords; k++) {
1994+
tmp = ((keyword_ty)asdl_seq_GET(keywords, k))->arg;
1995+
if (!PyUnicode_Compare(tmp, key)) {
1996+
ast_error(CHILD(ch, 0), "keyword argument repeated");
1997+
return NULL;
1998+
}
1999+
}
19922000
e = ast_for_expr(c, CHILD(ch, 2));
19932001
if (!e)
19942002
return NULL;

0 commit comments

Comments
 (0)