Skip to content

Commit 25cb613

Browse files
skirpichevAA-Turneraisk
authored
Document how to use *args in Argument Clinic (#1629)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Co-authored-by: AN Long <aisk1988@gmail.com>
1 parent ec8e6ba commit 25cb613

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

development-tools/clinic.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,37 @@ You can still use a self converter, a return converter, and specify
14951495
a *type* argument to the object converter for :c:macro:`METH_O`.
14961496

14971497

1498+
How to convert ``*args`` parameters (starargs / var-positional)
1499+
---------------------------------------------------------------
1500+
1501+
There are two converters suitable for ``*args``: *array* and *tuple*.
1502+
1503+
Using the *array* converter will provide the implementation function with
1504+
a C array *args* of type of :c:type:`PyObject * <PyObject>` and the number
1505+
of items in the array as :c:type:`Py_ssize_t` *args_length*.
1506+
For example::
1507+
1508+
/*[clinic input]
1509+
var_positional_sample
1510+
1511+
spam: int
1512+
*args: array
1513+
[clinic start generated code]*/
1514+
1515+
Using the *tuple* converter will provide the implementation function with
1516+
a standard :c:type:`PyTupleObject`.
1517+
For example::
1518+
1519+
/*[clinic input]
1520+
var_positional_sample
1521+
1522+
spam: int
1523+
*args: tuple
1524+
[clinic start generated code]*/
1525+
1526+
.. versionadded:: 3.11
1527+
1528+
14981529
How to convert ``tp_new`` and ``tp_init`` functions
14991530
---------------------------------------------------
15001531

0 commit comments

Comments
 (0)