mirror of
https://github.com/python/cpython.git
synced 2025-07-29 14:15:07 +00:00
#3219 repeated keyword arguments aren't allowed in function calls anymore
This commit is contained in:
parent
1f40c8a8d7
commit
175e4d9663
3 changed files with 19 additions and 0 deletions
|
@ -417,6 +417,11 @@ leading to spurious errors.
|
||||||
...
|
...
|
||||||
SyntaxError: can't assign to function call (<doctest test.test_syntax[48]>, line 6)
|
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
|
import re
|
||||||
|
|
|
@ -21,6 +21,10 @@ Core and Builtins
|
||||||
slice(None, 10, -1).indices(10) returns (9, 9, -1) instead of (9,
|
slice(None, 10, -1).indices(10) returns (9, 9, -1) instead of (9,
|
||||||
10, -1).
|
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
|
Build
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
|
10
Python/ast.c
10
Python/ast.c
|
@ -1912,6 +1912,8 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
|
||||||
else {
|
else {
|
||||||
keyword_ty kw;
|
keyword_ty kw;
|
||||||
identifier key;
|
identifier key;
|
||||||
|
int k;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
/* CHILD(ch, 0) is test, but must be an identifier? */
|
/* CHILD(ch, 0) is test, but must be an identifier? */
|
||||||
e = ast_for_expr(c, CHILD(ch, 0));
|
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;
|
key = e->v.Name.id;
|
||||||
if (!forbidden_check(c, CHILD(ch, 0), PyBytes_AS_STRING(key)))
|
if (!forbidden_check(c, CHILD(ch, 0), PyBytes_AS_STRING(key)))
|
||||||
return NULL;
|
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));
|
e = ast_for_expr(c, CHILD(ch, 2));
|
||||||
if (!e)
|
if (!e)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue