Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to use varargs in Argument Clinic #1277

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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,
prepending the parameter name with ``*`` ,
and the parameter should use the ``object`` converter::
Copy link
Member

Choose a reason for hiding this comment

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

What happens if I use something else? E.g., what if I want to accept an arbitrary number of ints?

Also, what type does the implementation function receive?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for the review! I have added a new paragraph to explain more about it.


/*[clinic input]
var_positional_sample

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

The implementation function will receive var-positional arguments
as a tuple, you can either use the tuple directly
or parsing them into C types using :c:func:`!PyArg_Parse*` functions.
aisk marked this conversation as resolved.
Show resolved Hide resolved

.. versionadded:: 3.11
willingc marked this conversation as resolved.
Show resolved Hide resolved


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

Expand Down
Loading