gh-78416: Allow "|" after "$" for required keyword-only arguments - #155331
Draft
serhiy-storchaka wants to merge 1 commit into
Draft
gh-78416: Allow "|" after "$" for required keyword-only arguments#155331serhiy-storchaka wants to merge 1 commit into
serhiy-storchaka wants to merge 1 commit into
Conversation
This was referenced Aug 7, 2026
Documentation build overview
|
…eTupleAndKeywords() "|" can now be specified after "$" to end the required keyword-only arguments, so that they can be mixed with optional arguments. The keyword-only arguments are required until "|", if it follows, and inherit the state of the positional arguments otherwise. Argument Clinic uses this if "$" alone cannot express the signature, so that such functions can now use the limited C API. It also no longer rejects a required keyword-only parameter after an optional positional one.
serhiy-storchaka
force-pushed
the
getargs-required-kwonly-bar
branch
from
August 7, 2026 15:27
7805b1c to
625e7b2
Compare
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PyArg_ParseTupleAndKeywords()supports only three of the four kinds of parameters: keyword-only arguments are either all required ("OO$OO") or all optional ("O|O$O"), sof(a, b=None, *, c, d=None)cannot be expressed.This is one of three alternative implementations, made for comparison as suggested in the issue; this one adds no new syntax at all (taleinat's proposal).
|may now follow$, ending the required keyword-only arguments:"O|O$O|O"corresponds tof(a, b=None, *, c, d=None). Without a|after it,$keeps its current meaning exactly. Every format it gives meaning to is aSystemErrortoday, so nothing that works can change.Argument Clinic uses the trailing
|when$alone cannot express the signature, so such functions can now use the limited C API, and it no longer rejects a required keyword-only parameter after an optional positional one.It is the smallest change to
Python/getargs.cof the three, because the"$ before |"error disappears entirely. Against that: whether an argument after$is required now depends on text further right, so the scanner must look ahead; and a forgotten trailing|silently makes required keyword-only arguments optional, since"O|O$O|"isf(a, b=None, *, c)while"O|O$O"isf(a, b=None, *, c=None)— both legal, neither diagnosable.The other two alternatives: #155329, #155330.