Skip to content

Commit 1e70fda

Browse files
committed
py/compile: Raise SyntaxError if positional args are given after */**.
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+.
1 parent 696fcde commit 1e70fda

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

py/compile.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,6 +2308,10 @@ STATIC void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_t pn_ar
23082308
}
23092309
} else {
23102310
normal_argument:
2311+
if (star_flags) {
2312+
compile_syntax_error(comp, args[i], "non-keyword arg after */**");
2313+
return;
2314+
}
23112315
if (n_keyword > 0) {
23122316
compile_syntax_error(comp, args[i], "non-keyword arg after keyword arg");
23132317
return;

tests/basics/python34.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ def test_syntax(code):
2020
print("SyntaxError")
2121
test_syntax("f(*a, *b)") # can't have multiple * (in 3.5 we can)
2222
test_syntax("f(**a, **b)") # can't have multiple ** (in 3.5 we can)
23+
test_syntax("f(*a, b)") # can't have positional after *
24+
test_syntax("f(**a, b)") # can't have positional after **
2325
test_syntax("() = []") # can't assign to empty tuple (in 3.6 we can)
2426
test_syntax("del ()") # can't delete empty tuple (in 3.6 we can)
2527

tests/basics/python34.py.exp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ SyntaxError
77
SyntaxError
88
SyntaxError
99
SyntaxError
10+
SyntaxError
11+
SyntaxError
1012
3.4
1113
3 4

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy