GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||
GeezerVison is showing github.com — gh-157407: Argument Clinic: parse positional-only `defining_class` methods without `_PyArg_Parser` by eendebakpt · Pull Request #157483 · python/cpython Conversation
|
.text |
read-only data | .data |
|
|---|---|---|---|
| Windows x64 (MSVC, LTCG) | −6352 | −4708 | −10512 |
| Linux x86-64 (gcc -O3)* | −2592 | −1144 | −5664 |
* excluding _decimal, _sqlite3, _dbm and _gdbm, which were not built. Linux also drops 4872 bytes of .rela.dyn.
Changed error messages: these methods now raise the same TypeError messages as other positional-only methods,:
| call | before | after |
|---|---|---|
compressobj().compress() |
compress() takes exactly 1 positional argument (0 given) |
compress expected 1 argument, got 0 |
compressobj().compress(b'', b'') |
compress() takes at most 1 argument (2 given) |
compress expected 1 argument, got 2 |
Pickler(f).dump(obj=1) |
dump() takes exactly 1 positional argument (0 given) |
dump() takes no keyword arguments |
This 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
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…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) <[email protected]>
# Conflicts: # Modules/_ctypes/clinic/_ctypes.c.h # Modules/_io/clinic/bufferedio.c.h # Modules/_io/clinic/textio.c.h # Modules/clinic/_asynciomodule.c.h
Co-Authored-By: Claude Fable 5.1 <[email protected]>
…y-defclass-2 # Conflicts: # Modules/_io/clinic/bufferedio.c.h # Modules/_io/clinic/fileio.c.h # Modules/_io/clinic/iobase.c.h # Modules/_io/clinic/textio.c.h # Modules/_io/clinic/winconsoleio.c.h
…y-defclass-2 # Conflicts: # Modules/_decimal/clinic/_decimal.c.h # Modules/clinic/_dbmmodule.c.h # Modules/clinic/_elementtree.c.h # Modules/clinic/_gdbmmodule.c.h # Modules/clinic/_zoneinfo.c.h
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.