mirror of https://github.com/python/cpython
Disallow function calls like foo(None=1).
Backport from py3k rev. 55708 by Guido. (backport from rev. 55802)
This commit is contained in:
parent
c98da3d811
commit
73c958aced
|
@ -37,6 +37,9 @@ class TestSpecifics(unittest.TestCase):
|
||||||
def test_syntax_error(self):
|
def test_syntax_error(self):
|
||||||
self.assertRaises(SyntaxError, compile, "1+*3", "filename", "exec")
|
self.assertRaises(SyntaxError, compile, "1+*3", "filename", "exec")
|
||||||
|
|
||||||
|
def test_none_keyword_arg(self):
|
||||||
|
self.assertRaises(SyntaxError, compile, "f(None=1)", "<string>", "exec")
|
||||||
|
|
||||||
def test_duplicate_global_local(self):
|
def test_duplicate_global_local(self):
|
||||||
try:
|
try:
|
||||||
exec 'def f(a): global a; a = 1'
|
exec 'def f(a): global a; a = 1'
|
||||||
|
|
13
Python/ast.c
13
Python/ast.c
|
@ -1855,13 +1855,18 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
|
||||||
* then is very confusing.
|
* then is very confusing.
|
||||||
*/
|
*/
|
||||||
if (e->kind == Lambda_kind) {
|
if (e->kind == Lambda_kind) {
|
||||||
ast_error(CHILD(ch, 0), "lambda cannot contain assignment");
|
ast_error(CHILD(ch, 0),
|
||||||
return NULL;
|
"lambda cannot contain assignment");
|
||||||
|
return NULL;
|
||||||
} else if (e->kind != Name_kind) {
|
} else if (e->kind != Name_kind) {
|
||||||
ast_error(CHILD(ch, 0), "keyword can't be an expression");
|
ast_error(CHILD(ch, 0), "keyword can't be an expression");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
key = e->v.Name.id;
|
key = e->v.Name.id;
|
||||||
|
if (!strcmp(PyString_AS_STRING(key), "None")) {
|
||||||
|
ast_error(CHILD(ch, 0), "assignment to None");
|
||||||
|
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…
Reference in New Issue