Skip to content

Commit 73c958a

Browse files
committed
Disallow function calls like foo(None=1).
Backport from py3k rev. 55708 by Guido. (backport from rev. 55802)
1 parent c98da3d commit 73c958a

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

‎Lib/test/test_compile.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ def test_argument_handling(self):
3737
def test_syntax_error(self):
3838
self.assertRaises(SyntaxError, compile, "1+*3", "filename", "exec")
3939

40+
def test_none_keyword_arg(self):
41+
self.assertRaises(SyntaxError, compile, "f(None=1)", "<string>", "exec")
42+
4043
def test_duplicate_global_local(self):
4144
try:
4245
exec 'def f(a): global a; a = 1'

‎Python/ast.c‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,13 +1855,18 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
18551855
* then is very confusing.
18561856
*/
18571857
if (e->kind == Lambda_kind) {
1858-
ast_error(CHILD(ch, 0), "lambda cannot contain assignment");
1859-
return NULL;
1858+
ast_error(CHILD(ch, 0),
1859+
"lambda cannot contain assignment");
1860+
return NULL;
18601861
} else if (e->kind != Name_kind) {
1861-
ast_error(CHILD(ch, 0), "keyword can't be an expression");
1862-
return NULL;
1862+
ast_error(CHILD(ch, 0), "keyword can't be an expression");
1863+
return NULL;
18631864
}
18641865
key = e->v.Name.id;
1866+
if (!strcmp(PyString_AS_STRING(key), "None")) {
1867+
ast_error(CHILD(ch, 0), "assignment to None");
1868+
return NULL;
1869+
}
18651870
e = ast_for_expr(c, CHILD(ch, 2));
18661871
if (!e)
18671872
return NULL;

0 commit comments

Comments
 (0)