Skip to content

Commit 2f19e5d

Browse files
gh-74366: Fix the documentation of "$" in PyArg_ParseTupleAndKeywords()
The keyword-only arguments are not always optional: they are required if "|" was not specified before "$". Document also that "|" cannot be specified after "$", and add examples for "|" and "$".
1 parent 4130af1 commit 2f19e5d

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

Doc/c-api/arg.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,13 +399,18 @@ inside nested parentheses. They are:
399399
their default value --- when an optional argument is not specified,
400400
:c:func:`PyArg_ParseTuple` does not touch the contents of the corresponding C
401401
variable(s).
402+
For example, the format string ``"OO|OO"`` corresponds to the Python
403+
signature ``f(a, b, c=None, d=None)``.
402404

403405
``$``
404406
:c:func:`PyArg_ParseTupleAndKeywords` only:
405407
Indicates that the remaining arguments in the Python argument list are
406-
keyword-only. Currently, all keyword-only arguments must also be optional
407-
arguments, so ``|`` must always be specified before ``$`` in the format
408-
string.
408+
keyword-only.
409+
They are optional if ``|`` was specified before ``$``, and required otherwise.
410+
``|`` cannot be specified after ``$``.
411+
For example, the format string ``"O|O$O"`` corresponds to the Python
412+
signature ``f(a, b=None, *, c=None)``,
413+
and the format string ``"OO$OO"`` corresponds to ``f(a, b, *, c, d)``.
409414

410415
.. versionadded:: 3.3
411416

0 commit comments

Comments
 (0)