Skip to content

Re-work support of var-positional parameters in Argument Clinic #122943

Closed
@serhiy-storchaka

Description

@serhiy-storchaka

When fixing some bugs (#118814, #122688) I noticed also design problems in _PyArg_UnpackKeywordsWithVararg().

  • Its vararg parameter is always equal to maxpos, 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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions