Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 966
Document how to use varargs in Argument Clinic#1629
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
skirpichev commented Aug 12, 2025 • edited by github-actions bot
Loading Uh oh!
There was an error while loading. Please reload this page.
edited by github-actions bot
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Jelle Zijlstra <[email protected]> Co-authored-by: Sergey B Kirpichev <[email protected]>
skirpichev commented Aug 12, 2025
This is a minor correction of closed pr #1277 (now var-positional arguments passed a C array). The rest looks fine for me. |
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Sergey B Kirpichev <[email protected]>
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Adam Turner <[email protected]>
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
AA-Turner left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
skirpichev commented Aug 16, 2025
It's not removed, just an alias for tuple. |
development-tools/clinic.rst Outdated
| 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. |
There was a problem hiding this comment.
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.
| 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]*/ |
There was a problem hiding this comment.
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.
Co-authored-by: Adam Turner <[email protected]>
25cb613 into python:mainUh oh!
There was an error while loading. Please reload this page.
📚 Documentation preview 📚: https://cpython-devguide--1629.org.readthedocs.build/