gh-157407: Argument Clinic: parse positional-only defining_class methods without _PyArg_Parser - #157483
Open
eendebakpt wants to merge 1 commit into
Open
gh-157407: Argument Clinic: parse positional-only defining_class methods without _PyArg_Parser#157483eendebakpt wants to merge 1 commit into
defining_class methods without _PyArg_Parser#157483eendebakpt wants to merge 1 commit into
Conversation
…s methods
A method that takes a defining class and whose other parameters are all
positional-only (e.g. decimal.Decimal.from_float) was routed through
Argument Clinic's generic keyword path: it emitted a static _PyArg_Parser,
an (empty) keyword tuple and an _PyArg_UnpackKeywords() call, even though
it accepts no keyword arguments.
Such methods now go through parse_pos_only(): the wrapper still uses the
mandatory METH_METHOD|METH_FASTCALL|METH_KEYWORDS convention (the only one
that delivers the defining class), but it rejects keywords with
_PyArg_NoKwnames() and reads positional arguments directly, with no
parser, keyword tuple or argsbuf.
This converts 135 methods across 19 clinic headers, removing the static
_PyArg_Parser, the keyword arrays/tuples and the per-call
_PyArg_UnpackKeywords() + parser_init() overhead for each.
_PyArg_NoKwnames() is now exported (PyAPI_FUNC) so generated code in
shared extension modules can use it, like _PyArg_NoKeywords().
Error messages for these methods now match ordinary positional-only
functions ("expected ... arguments" / "takes no keyword arguments"
instead of the _PyArg_UnpackKeywords phrasing); affected stdlib tests
are updated accordingly.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
eendebakpt
requested review from
AA-Turner,
ericsnowcurrently and
erlend-aasland
as code owners
September 14, 2026 11:02
methane
approved these changes
Sep 14, 2026
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.
Methods taking a
defining_classwhose other parameters are all positional-only (e.g.Decimal.from_float) used the keyword path: a static_PyArg_Parserand a_PyArg_UnpackKeywords()call. They now use_PyArg_NoKwnames().Typical code change:
This converts 135 methods in 19 clinic headers.
_PyArg_NoKwnames()is now exported for shared extension modules.Size change in bytes:
.text.data* excluding
_decimal,_sqlite3,_dbmand_gdbm, which were not built. Linux also drops 4872 bytes of.rela.dyn.Changed error messages: these methods now raise the same
TypeErrormessages as other positional-only methods,:compressobj().compress()compress() takes exactly 1 positional argument (0 given)compress expected 1 argument, got 0compressobj().compress(b'', b'')compress() takes at most 1 argument (2 given)compress expected 1 argument, got 2Pickler(f).dump(obj=1)dump() takes exactly 1 positional argument (0 given)dump() takes no keyword argumentsThis is arguably more consistent, but a small change in error messages.
Performance seems slightly improved (but within noise, no not quoting any numbers).
Generated with Claude Code