diff options
author | colorfulappl <colorfulappl@qq.com> | 2022-11-24 19:56:50 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-24 19:56:50 (GMT) |
commit | 0da728387c99fe6c127b070f2d250dc5bdd62ee5 (patch) | |
tree | d160fe884cbaacdeb17c72e8fc8b8d23cec249dd /Python | |
parent | 351842b46a7cb3c3f23b200d532cf29e4557ad4b (diff) | |
download | cpython-0da728387c99fe6c127b070f2d250dc5bdd62ee5.zip cpython-0da728387c99fe6c127b070f2d250dc5bdd62ee5.tar.gz cpython-0da728387c99fe6c127b070f2d250dc5bdd62ee5.tar.bz2 |
gh-64490: Fix bugs in argument clinic varargs processing (#32092)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/getargs.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/Python/getargs.c b/Python/getargs.c index 748209d..0167dd7 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -2598,7 +2598,25 @@ _PyArg_UnpackKeywordsWithVararg(PyObject *const *args, Py_ssize_t nargs, current_arg = NULL; } - buf[i + vararg + 1] = current_arg; + /* If an arguments is passed in as a keyword argument, + * it should be placed before `buf[vararg]`. + * + * For example: + * def f(a, /, b, *args): + * pass + * f(1, b=2) + * + * This `buf` array should be: [1, 2, NULL]. + * In this case, nargs < vararg. + * + * Otherwise, we leave a place at `buf[vararg]` for vararg tuple + * so the index is `i + 1`. */ + if (nargs < vararg) { + buf[i] = current_arg; + } + else { + buf[i + 1] = current_arg; + } if (current_arg) { --nkwargs; |