Uh oh!
There was an error while loading. Please reload this page.
gh-64490: Argument Clinic: Add support for **kwds - #138344
Conversation
This adds a scaffold of support, initially only working with strictly positional-only arguments. The FASTCALL calling convention is not yet supported.
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
commented
Sep 2, 2025
Yes, but I didn't want to make this PR bigger by including them. A |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
picnixz
left a comment
There was a problem hiding this comment.
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.
Uh oh!
There was an error while loading. Please reload this page.
serhiy-storchaka
left a comment
There was a problem hiding this comment.
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).
Uh oh!
There was an error while loading. Please reload this page.
# Conflicts: # Lib/test/test_clinic.py
erlend-aasland
left a comment
There was a problem hiding this comment.
Thanks, looks good!
serhiy-storchaka
left a comment
There was a problem hiding this comment.
Thank you for addressing all my comments. It seems that the tests have not expose any bugs in code. Few more suggestions and nitpicks.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| [ | ||
| **kwds: dict | ||
| ] |
There was a problem hiding this comment.
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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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