Issue #26282: PyArg_ParseTupleAndKeywords() and Argument Clinic now support

positional-only and keyword parameters in the same function.
This commit is contained in:
Serhiy Storchaka 2016-06-09 16:30:29 +03:00
parent 339880809a
commit f41b82fb19
9 changed files with 210 additions and 72 deletions

View file

@ -1028,6 +1028,21 @@ getargs_keyword_only(PyObject *self, PyObject *args, PyObject *kwargs)
return Py_BuildValue("iii", required, optional, keyword_only);
}
/* test PyArg_ParseTupleAndKeywords positional-only arguments */
static PyObject *
getargs_positional_only_and_keywords(PyObject *self, PyObject *args, PyObject *kwargs)
{
static char *keywords[] = {"", "", "keyword", NULL};
int required = -1;
int optional = -1;
int keyword = -1;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i|ii", keywords,
&required, &optional, &keyword))
return NULL;
return Py_BuildValue("iii", required, optional, keyword);
}
/* Functions to call PyArg_ParseTuple with integer format codes,
and return the result.
*/
@ -3963,6 +3978,9 @@ static PyMethodDef TestMethods[] = {
METH_VARARGS|METH_KEYWORDS},
{"getargs_keyword_only", (PyCFunction)getargs_keyword_only,
METH_VARARGS|METH_KEYWORDS},
{"getargs_positional_only_and_keywords",
(PyCFunction)getargs_positional_only_and_keywords,
METH_VARARGS|METH_KEYWORDS},
{"getargs_b", getargs_b, METH_VARARGS},
{"getargs_B", getargs_B, METH_VARARGS},
{"getargs_h", getargs_h, METH_VARARGS},