summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2008-07-01 19:34:52 +0000
committerBenjamin Peterson <benjamin@python.org>2008-07-01 19:34:52 +0000
commit175e4d96631cad3e3ca230d97d51374b00d9e973 (patch)
treeb3118ec2d106a23aff7c4e932d9d35c402e7b228
parent1f40c8a8d70ea8789c3ffca126e0d3cce41d0f7d (diff)
downloadcpython-git-175e4d96631cad3e3ca230d97d51374b00d9e973.tar.gz
#3219 repeated keyword arguments aren't allowed in function calls anymore
-rw-r--r--Lib/test/test_syntax.py5
-rw-r--r--Misc/NEWS4
-rw-r--r--Python/ast.c10
3 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py
index d0433034db..6e60706ac3 100644
--- a/Lib/test/test_syntax.py
+++ b/Lib/test/test_syntax.py
@@ -417,6 +417,11 @@ leading to spurious errors.
...
SyntaxError: can't assign to function call (<doctest test.test_syntax[48]>, line 6)
+>>> f(a=23, a=234)
+Traceback (most recent call last):
+ ...
+SyntaxError: keyword argument repeated (<doctest test.test_syntax[49]>, line 1)
+
"""
import re
diff --git a/Misc/NEWS b/Misc/NEWS
index 1dd586fcb4..af95f94aff 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -21,6 +21,10 @@ Core and Builtins
slice(None, 10, -1).indices(10) returns (9, 9, -1) instead of (9,
10, -1).
+- Issue #3219: Calling a function with repeated keyword arguments, f(a=2, a=23),
+ would not cause a syntax error. This was regression from 2.4 caused by the
+ switch to the new compiler.
+
Build
-----
diff --git a/Python/ast.c b/Python/ast.c
index 4d874af5c2..dc22478157 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -1912,6 +1912,8 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
else {
keyword_ty kw;
identifier key;
+ int k;
+ char *tmp;
/* CHILD(ch, 0) is test, but must be an identifier? */
e = ast_for_expr(c, CHILD(ch, 0));
@@ -1933,6 +1935,14 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
key = e->v.Name.id;
if (!forbidden_check(c, CHILD(ch, 0), PyBytes_AS_STRING(key)))
return NULL;
+ for (k = 0; k < nkeywords; k++) {
+ tmp = PyString_AS_STRING(
+ ((keyword_ty)asdl_seq_GET(keywords, k))->arg);
+ if (!strcmp(tmp, PyString_AS_STRING(key))) {
+ ast_error(CHILD(ch, 0), "keyword argument repeated");
+ return NULL;
+ }
+ }
e = ast_for_expr(c, CHILD(ch, 2));
if (!e)
return NULL;