FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Document how to use varargs in Argument Clinic by skirpichev · Pull Request #1629 · python/devguide · GitHub

Repository navigation

Document how to use varargs in Argument Clinic - #1629

Merged
AA-Turner merged 6 commits into
python:mainfrom
skirpichev:clinic-varpos
Aug 18, 2025
Merged

AA-Turner merged 6 commits into
python:mainfrom
skirpichev:clinic-varpos

Conversation

skirpichev commented Aug 12, 2025 •
edited by github-actions Bot
Loading

Copy link
Copy Markdown
Member

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>

Copy link
Copy Markdown
Member Author

This is a minor correction of closed pr #1277 (now var-positional arguments passed a C array). The rest looks fine for me.

Comment thread development-tools/clinic.rst Outdated
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Comment thread development-tools/clinic.rst Outdated
Comment thread development-tools/clinic.rst Outdated
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Comment thread development-tools/clinic.rst Outdated
Comment thread development-tools/clinic.rst Outdated

AA-Turner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

We should mention both the tuple and array converters, they do different things. Notably array results in PyObject * const *args and Py_ssize_t args_length, whereas tuple just passes a regular PyTupleObject.

Also, I found the PR where : object was removed (python/cpython#126560 by @serhiy-storchaka)

Copy link
Copy Markdown
Member Author

Also, I found the PR where : object was removed

It's not removed, just an alias for tuple.

skirpichev requested a review from AA-Turner August 16, 2025 01:48
Comment thread development-tools/clinic.rst Outdated
Comment on lines +1498 to +1514
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

IMO, it's too verbose. But OK.

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
AA-Turner merged commit 25cb613 into python:main Aug 18, 2025
skirpichev deleted the clinic-varpos branch August 18, 2025 01:36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL