Closed
Description
When fixing some bugs (#118814, #122688) I noticed also design problems in _PyArg_UnpackKeywordsWithVararg()
.
- Its
vararg
parameter is always equal tomaxpos
, therefore it is redundant. - Inserting a new tuple between values for positional and keyword-only parameters adds complexity in the
_PyArg_UnpackKeywordsWithVararg()
code which caused bugs. - Since it is the only argument value which is a strong reference, it adds complexity for cleanup after calling
_PyArg_UnpackKeywordsWithVararg()
. - This large code is mostly a duplication of
_PyArg_UnpackKeywords()
. - But it lacks some microoptimizations.
- And produces wrong error messages in some corner cases.
- Also some cases (like var-positional parameter after optional parameters) were not supported.
So I re-worked it in several steps:
- Removed the
vararg
parameter from_PyArg_UnpackKeywordsWithVararg()
. - Moved creation of the tuple for var-positional parameter out from
_PyArg_UnpackKeywordsWithVararg()
. - Refactored Argument Clinic code: it now generates similar code for var-positional parameter in functions with and without keyword parameters. The generated code is now more optimal and more cases are now supported. This is a large step.
- Finally,
_PyArg_UnpackKeywordsWithVararg()
was merged with_PyArg_UnpackKeywords()
which now got a new flag.
Linked PRs
- gh-122943: Rework support of var-positional parameter in Argument Clinic #122945
- gh-122943: Remove the object converter for var-positional parameter #126560
- gh-122943: Add the varpos parameter in _PyArg_UnpackKeywords #126564
- gh-122943: Move code generation for var-positional parameter to converters #126575