Commit f72d032
gh-136681: Drop _PyArg_Parser for positional-only defining-class 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>1 parent fb46c67 commit f72d032
26 files changed
Lines changed: 644 additions & 2399 deletions
File tree
- Include/internal
- Lib/test
- test_sqlite3
- Misc/NEWS.d/next/Core_and_Builtins
- Modules
- _ctypes/clinic
- _decimal/clinic
- _io/clinic
- _sqlite/clinic
- cjkcodecs/clinic
- clinic
- Tools/clinic/libclinic
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6002 | 6002 | | |
6003 | 6003 | | |
6004 | 6004 | | |
6005 | | - | |
6006 | | - | |
6007 | | - | |
6008 | | - | |
6009 | | - | |
6010 | | - | |
6011 | | - | |
6012 | | - | |
6013 | | - | |
6014 | | - | |
6015 | | - | |
6016 | | - | |
6017 | | - | |
6018 | 6005 | | |
6019 | 6006 | | |
6020 | 6007 | | |
6021 | | - | |
| 6008 | + | |
| 6009 | + | |
| 6010 | + | |
| 6011 | + | |
6022 | 6012 | | |
6023 | 6013 | | |
6024 | 6014 | | |
| |||
6032 | 6022 | | |
6033 | 6023 | | |
6034 | 6024 | | |
6035 | | - | |
| 6025 | + | |
6036 | 6026 | | |
6037 | 6027 | | |
6038 | 6028 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4898 | 4898 | | |
4899 | 4899 | | |
4900 | 4900 | | |
4901 | | - | |
| 4901 | + | |
4902 | 4902 | | |
4903 | 4903 | | |
4904 | 4904 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
450 | 450 | | |
451 | 451 | | |
452 | 452 | | |
453 | | - | |
| 453 | + | |
454 | 454 | | |
455 | 455 | | |
456 | 456 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
720 | 720 | | |
721 | 721 | | |
722 | 722 | | |
723 | | - | |
| 723 | + | |
724 | 724 | | |
725 | 725 | | |
726 | 726 | | |
| |||
767 | 767 | | |
768 | 768 | | |
769 | 769 | | |
770 | | - | |
| 770 | + | |
771 | 771 | | |
772 | 772 | | |
773 | 773 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
0 commit comments