Index: Python/ast.c =================================================================== --- Python/ast.c (Revision 45742) +++ Python/ast.c (Arbeitskopie) @@ -1702,7 +1702,7 @@ argument: [test '='] test [gen_for] # Really [keyword '='] test */ - int i, nargs, nkeywords, ngens; + int i, nargs, nkeywords, ngens, seen_kw = 0; asdl_seq *args; asdl_seq *keywords; expr_ty vararg = NULL, kwarg = NULL; @@ -1747,6 +1747,10 @@ if (TYPE(ch) == argument) { expr_ty e; if (NCH(ch) == 1) { + if (seen_kw) { + ast_error(CHILD(ch, 0), "non-keyword arg after keyword arg"); + return NULL; + } e = ast_for_expr(c, CHILD(ch, 0)); if (!e) return NULL; @@ -1786,6 +1790,7 @@ if (!kw) return NULL; asdl_seq_SET(keywords, nkeywords++, kw); + seen_kw = 1; } } else if (TYPE(ch) == STAR) { Index: Lib/test/test_syntax.py =================================================================== --- Lib/test/test_syntax.py (Revision 45742) +++ Lib/test/test_syntax.py (Arbeitskopie) @@ -290,6 +290,9 @@ :""") self._check_error(source, "nested scope") + def test_kwargs_last(self): + self._check_error("int(base=10, '2')", "non-keyword arg") + def test_main(): test_support.run_unittest(SyntaxTestCase) from test import test_syntax