Skip to content
Merged
Changes from 5 commits
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
21 changes: 21 additions & 0 deletions development-tools/clinic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,27 @@ You can still use a self converter, a return converter, and specify
a *type* argument to the object converter for :c:macro:`METH_O`.


How to convert var-positional parameter functions
-------------------------------------------------

To convert a var-positional parameter function, prepend the parameter name
with ``*`` and use the the ``array`` converter.
For example::

/*[clinic input]
var_positional_sample

foo: int
*args: array
[clinic start generated code]*/

The implementation function will receive var-positional arguments as C array
*args* of :c:type:`PyObject * <PyObject>`. Alternatively, you could use
``tuple`` converter to pass a regular :c:type:`PyTupleObject` as argument.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A suggested rephrasing to split tuple and array. I've also switched to saying *args instead of emphasising var-positional, the documentation uses *args or starargs, when discussing the feature in the language reference, it seems to be only internal to Clinic to say varpos.

Suggested change
How to convert var-positional parameter functions
-------------------------------------------------
To convert a var-positional parameter function, prepend the parameter name
with ``*`` and use the the ``array`` converter.
For example::
/*[clinic input]
var_positional_sample
foo: int
*args: array
[clinic start generated code]*/
The implementation function will receive var-positional arguments as C array
*args* of :c:type:`PyObject * <PyObject>`. Alternatively, you could use
``tuple`` converter to pass a regular :c:type:`PyTupleObject` as argument.
How to convert ``*args`` parameters (starargs / var-positional)
---------------------------------------------------------------
There are two converters suitable for ``*args``: *array* and *tuple*.
Using the *array* converter will provide the implementation function with
a C array *args* of type of :c:type:`PyObject * <PyObject>` and the number
of items in the array as :c:type:`Py_ssize_t` *args_length*.
For example::
/*[clinic input]
var_positional_sample
spam: int
*args: array
[clinic start generated code]*/
Using the *tuple* converter will provide the implementation function with
a standard :c:type:`PyTupleObject`.
For example::
/*[clinic input]
var_positional_sample
spam: int
*args: tuple
[clinic start generated code]*/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, it's too verbose. But OK.


.. versionadded:: 3.11


How to convert ``tp_new`` and ``tp_init`` functions
---------------------------------------------------

Expand Down
Loading