Skip to content

Commit

Permalink
py/compile: Raise SyntaxError if positional args are given after */**.
Browse files Browse the repository at this point in the history
In CPython 3.4 this raises a SyntaxError.  In CPython 3.5+ having a
positional after * is allowed but uPy has the wrong semantics and passes
the arguments in the incorrect order.  To prevent incorrect use of a
function going unnoticed it is important to raise the SyntaxError in uPy,
until the behaviour is fixed to follow CPython 3.5+.
  • Loading branch information
dpgeorge committed Jun 14, 2017
1 parent 696fcde commit 1e70fda
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions py/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -2308,6 +2308,10 @@ STATIC void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_t pn_ar
}
} else {
normal_argument:
if (star_flags) {
compile_syntax_error(comp, args[i], "non-keyword arg after */**");
return;
}
if (n_keyword > 0) {
compile_syntax_error(comp, args[i], "non-keyword arg after keyword arg");
return;
Expand Down
2 changes: 2 additions & 0 deletions tests/basics/python34.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def test_syntax(code):
print("SyntaxError")
test_syntax("f(*a, *b)") # can't have multiple * (in 3.5 we can)
test_syntax("f(**a, **b)") # can't have multiple ** (in 3.5 we can)
test_syntax("f(*a, b)") # can't have positional after *
test_syntax("f(**a, b)") # can't have positional after **
test_syntax("() = []") # can't assign to empty tuple (in 3.6 we can)
test_syntax("del ()") # can't delete empty tuple (in 3.6 we can)

Expand Down
2 changes: 2 additions & 0 deletions tests/basics/python34.py.exp
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ SyntaxError
SyntaxError
SyntaxError
SyntaxError
SyntaxError
SyntaxError
3.4
3 4

0 comments on commit 1e70fda

Please sign in to comment.