py/compile: Reject *arg after keyword argument.

Document this in cpydiff and add a test with expected output
for coverage testing.

As discussed in #11441, the code growth from handling this
case seems to outweigh the benefit of implementing it
properly.

Closes: #11439

Signed-off-by: Jeff Epler <jepler@unpythonic.net>
This commit is contained in:
Jeff Epler
2026-04-02 21:40:11 -05:00
committed by Damien George
parent b67c55cb4f
commit 5ddc551bc4
4 changed files with 33 additions and 0 deletions
+8
View File
@@ -2421,6 +2421,14 @@ static void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_t pn_ar
compile_syntax_error(comp, (mp_parse_node_t)pns_arg, MP_ERROR_TEXT("* arg after **"));
return;
}
if (n_keyword) {
// Support for *arg after kwarg is a CPython feature omitted
// from MicroPython in order to reduce code size. See
// https://github.com/micropython/micropython/issues/11439 for
// more info.
compile_syntax_error(comp, (mp_parse_node_t)pns_arg, MP_ERROR_TEXT("* arg after kwarg"));
return;
}
#if MICROPY_DYNAMIC_COMPILER
if (i >= (size_t)mp_dynamic_compiler.small_int_bits - 1)
#else
+8
View File
@@ -0,0 +1,8 @@
# A CPython syntax feature not supported by MicroPython. For more information
# see `this issue <https://github.com/micropython/micropython/issues/11439>`_.
# and tests/cpydiff/core_function_star.py
try:
exec("f(y=1, *(3,))")
except SyntaxError as e:
print("SyntaxError")
+1
View File
@@ -0,0 +1 @@
SyntaxError
+16
View File
@@ -0,0 +1,16 @@
"""
categories: Core,Functions
description: ``*args`` cannot follow a keyword argument
cause: MicroPython is optimised for code space. For more information see `this issue <https://github.com/micropython/micropython/issues/11439>`_.
workaround: Re-order the arguments
"""
def f(x, y):
return x + y
try:
print(f(y=1, *(3,)))
except Exception as e:
print(e)