mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Issue #26282: PyArg_ParseTupleAndKeywords() and Argument Clinic now support
positional-only and keyword parameters in the same function.
This commit is contained in:
parent
339880809a
commit
f41b82fb19
9 changed files with 210 additions and 72 deletions
|
@ -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},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue