Skip to content

Conversation

AA-Turner
Copy link
Member

@AA-Turner AA-Turner commented Sep 1, 2025

This adds a scaffold of support, initially only working with strictly positional-only arguments. The FASTCALL calling convention is not yet supported.

I expect future PRs to relax these constraints.

Currently supported forms:

  • f(**kwds)
  • f(a, b, /, **kwds)
  • f(*args, **kwds)
  • f(a, b, /, *args, **kwds)

A

This adds a scaffold of support, initially only working with
strictly positional-only arguments. The FASTCALL calling
convention is not yet supported.
@vstinner
Copy link
Member

vstinner commented Sep 2, 2025

Do you plan to convert some functions to Argument Clinic thanks for this change? Or is it just for completeness?

@AA-Turner
Copy link
Member Author

Do you plan to convert some functions to Argument Clinic thanks for this change?

Yes, but I didn't want to make this PR bigger by including them.

A

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we test when someone uses **kwds: object or **kwds: int? Maybe we should enforce that **kwds is always annotated with "dict"? Also, I think more tests should be added for bad usage (for *args, the coverage is quite large, see test_clinic.py).

In addition, I would suggest using __clinic_kwds instead of kwds for the local variable when we have the (... *args, **kwargs) as someone could define kwds as being one of the positional arguments. This is what we do with args where we define __clinic_args if there are non-variadic parameters.

Those are just suggestions for fortifying the current interface though so they can be addressed later.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, looks right.

We need tests in Python that use functions defined in Modules/_testclinic.c. We need tests for different invalid combinations (var-keyword after keyword-or-positional or keyword-only parameters, different parameters after the var-keyword parameter, wrong converter for the var-keyword parameter, default value for the var-keyword parameter, the var-keyword parameter with groups, the var-keyword parameter with the defining_class parameter).

@serhiy-storchaka serhiy-storchaka removed their assignment Sep 8, 2025
Copy link
Contributor

@erlend-aasland erlend-aasland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good!

@AA-Turner AA-Turner enabled auto-merge (squash) September 18, 2025 13:09
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for addressing all my comments. It seems that the tests have not expose any bugs in code. Few more suggestions and nitpicks.

Comment on lines +1649 to +1651
[
**kwds: dict
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we are here, could you also add a case with a var-positional parameter inside an optional group?

And I think that it would be worth to add a test for different kinds of parameters (keyword-or-positional, keyword-only, var-positional, var-keyword) after a valid optional group (if there are no such tests yet). This may be a separate test method. Some of these cases can be supported in principle in future. We want to know if we enabled them accidentally.

@AA-Turner AA-Turner merged commit 1ebd726 into python:main Sep 18, 2025
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants