Bug report
Argument Clinic generates code which reads an optional positional argument even when it was not passed, if the function also has a **kwds parameter.
/*[clinic input]
m.f
a: object
b: object = None
/
**kwds: dict
[clinic start generated code]*/
generates
if (!_PyArg_CheckPositional("f", PyTuple_GET_SIZE(args), 1, 2)) {
goto exit;
}
a = PyTuple_GET_ITEM(args, 0);
b = PyTuple_GET_ITEM(args, 1);
so f(1) reads past the end of the argument tuple and usually crashes. For the same signature without **kwds the optional argument is guarded with if (nargs < 2) { goto skip_optional; }.
No function in the stdlib uses this combination yet, so it is only reproducible with new code — I ran into it while converting _csv.reader() (gh-155496).
Support for **kwds was added in 3.15 (gh-64490), so 3.15 and the main branch are affected.
Linked PRs
Bug report
Argument Clinic generates code which reads an optional positional argument even when it was not passed, if the function also has a
**kwdsparameter.generates
so
f(1)reads past the end of the argument tuple and usually crashes. For the same signature without**kwdsthe optional argument is guarded withif (nargs < 2) { goto skip_optional; }.No function in the stdlib uses this combination yet, so it is only reproducible with new code — I ran into it while converting
_csv.reader()(gh-155496).Support for
**kwdswas added in 3.15 (gh-64490), so 3.15 and the main branch are affected.Linked PRs