Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename to PyArg_ParseArray()
  • Loading branch information
vstinner committed Mar 6, 2026
commit 78510f5d0c55a8de84ac47242f5df4150cd2daea
4 changes: 2 additions & 2 deletions Doc/c-api/arg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ API Functions
}


.. c:function:: int PyArg_ParseVector(PyObject *const *args, Py_ssize_t nargs, const char *format, ...)
.. c:function:: int PyArg_ParseArray(PyObject *const *args, Py_ssize_t nargs, const char *format, ...)

Parse the parameters of a function that takes only vector parameters into
local variables (that is, a function using the :c:macro:`METH_FASTCALL`
Expand All @@ -527,7 +527,7 @@ API Functions
.. versionadded:: next


.. c:function:: int PyArg_ParseVectorAndKeywords(PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames, const char *format, const char * const *kwlist, ...)
.. c:function:: int PyArg_ParseArrayAndKeywords(PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames, const char *format, const char * const *kwlist, ...)

Parse the parameters of a function that takes both vector and keyword
parameters into local variables (that is, a function using the
Expand Down
4 changes: 2 additions & 2 deletions Include/cpython/modsupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# error "this header file must not be included directly"
#endif

PyAPI_FUNC(int) PyArg_ParseVector(
PyAPI_FUNC(int) PyArg_ParseArray(
PyObject *const *args,
Py_ssize_t nargs,
const char *format,
...);
PyAPI_FUNC(int) PyArg_ParseVectorAndKeywords(
PyAPI_FUNC(int) PyArg_ParseArrayAndKeywords(
PyObject *const *args,
Py_ssize_t nargs,
PyObject *kwnames,
Expand Down
6 changes: 3 additions & 3 deletions Lib/test/test_capi/test_modsupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ def test_negative_freethreading(self, modname, minor, build):


class TestModsupport(unittest.TestCase):
def test_pyarg_parsevector(self):
func = _testcapi.pyarg_parsevector
def test_pyarg_parsearray(self):
func = _testcapi.pyarg_parsearray
self.assertEqual(func(1, 2), (1, 2, 0))
self.assertEqual(func(1, 2, 3), (1, 2, 3))
self.assertRaises(TypeError, func, 1)
self.assertRaises(TypeError, func, "str", 2)

def test_funcandkeywords(self):
func = _testcapi.pyarg_parsevectorandkeywords
func = _testcapi.pyarg_parsearrayandkeywords
self.assertEqual(func(1, 2), (1, 2, 0))
self.assertEqual(func(1, 2, 3), (1, 2, 3))
self.assertEqual(func(1, b=2), (1, 2, 0))
Expand Down
20 changes: 10 additions & 10 deletions Modules/_testcapi/modsupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,34 @@ pyabiinfo_check(PyObject *Py_UNUSED(module), PyObject *args)
}

static PyObject *
pyarg_parsevector(PyObject* self, PyObject* const* args, Py_ssize_t nargs)
pyarg_parsearray(PyObject* self, PyObject* const* args, Py_ssize_t nargs)
{
int a, b, c = 0;
if (!PyArg_ParseVector(args, nargs, "ii|i", &a, &b, &c)) {
if (!PyArg_ParseArray(args, nargs, "ii|i", &a, &b, &c)) {
return NULL;
}
return Py_BuildValue("iii", a, b, c);
}

static PyObject *
pyarg_parsevectorandkeywords(PyObject* self, PyObject* const* args,
Py_ssize_t nargs, PyObject* kwnames)
pyarg_parsearrayandkeywords(PyObject* self, PyObject* const* args,
Py_ssize_t nargs, PyObject* kwnames)
{
int a, b, c = 0;
const char *kwlist[] = {"a", "b", "c", NULL};
if (!PyArg_ParseVectorAndKeywords(args, nargs, kwnames,
"ii|i", kwlist,
&a, &b, &c)) {
if (!PyArg_ParseArrayAndKeywords(args, nargs, kwnames,
"ii|i", kwlist,
&a, &b, &c)) {
return NULL;
}
return Py_BuildValue("iii", a, b, c);
}

static PyMethodDef TestMethods[] = {
{"pyabiinfo_check", pyabiinfo_check, METH_VARARGS},
{"pyarg_parsevector", _PyCFunction_CAST(pyarg_parsevector), METH_FASTCALL},
{"pyarg_parsevectorandkeywords",
_PyCFunction_CAST(pyarg_parsevectorandkeywords),
{"pyarg_parsearray", _PyCFunction_CAST(pyarg_parsearray), METH_FASTCALL},
{"pyarg_parsearrayandkeywords",
_PyCFunction_CAST(pyarg_parsearrayandkeywords),
METH_FASTCALL | METH_KEYWORDS},
{NULL},
};
Expand Down
10 changes: 5 additions & 5 deletions Python/getargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ _PyArg_ParseStack(PyObject *const *args, Py_ssize_t nargs, const char *format, .
}

int
PyArg_ParseVector(PyObject *const *args, Py_ssize_t nargs, const char *format, ...)
PyArg_ParseArray(PyObject *const *args, Py_ssize_t nargs, const char *format, ...)
{
va_list va;
va_start(va, format);
Expand All @@ -147,10 +147,10 @@ PyArg_ParseVector(PyObject *const *args, Py_ssize_t nargs, const char *format, .
}

int
PyArg_ParseVectorAndKeywords(PyObject *const *args, Py_ssize_t nargs,
PyObject *kwnames,
const char *format,
const char * const *kwlist, ...)
PyArg_ParseArrayAndKeywords(PyObject *const *args, Py_ssize_t nargs,
PyObject *kwnames,
const char *format,
const char * const *kwlist, ...)
{
if ((args == NULL && nargs != 0) ||
(kwnames != NULL && !PyTuple_Check(kwnames)) ||
Expand Down
Loading