First of all, thank you for writing a PEP! It’s a lot of work and an important service to the community, either improving the language or helping us move on if the idea is rejected. In that spirit, here are my issues with the current proposal, in the hope that they contribute to a better PEP or SC decision.
-
Why not use keyword-only arguments? They already provide a mechanism for named arguments of specific types, and show those locally without having to look at the definition of the TypedDict class in question.
-
Very little motivation has been given. Yes, refactoring code that uses
**kwargs
for clarity and static typing requires some work, but I’m not convinced that this PEP actually improves the situation.-
This PEP will also require a large amount of work by every (mostly volunteer) maintainer of a tool that deals with type annotations. This is already underway in static type checkers, but will also be required in enforcement tools such as beartype and typeguard, serialization libraries like Pydantic, testing tools including Hypothesis, etc., and is probably unsupportable in AST-based static analysis tools.
-
The linked thread notes that “in situations with many heterogeneous options listing all options in the signature could be verbose and will require rewriting some existing code”. If there are too many options to put in the function signature, I’d prefer
options: OptionsDict
(or some other config object) over**options: **OptionsDict
.
-
-
A few years ago I went through matplotlib converting
**kwargs
into explicit parameters, and found a pile of explicit bugs in the process where parameters would be silently dropped, overridden, or passed but go unused. Even with this PEP, using**kwargs
makes it much harder to detect such problems, or for users to know what can be passed without unrealistically comprehensive documentation - and even then it’s harder to see when it goes out of date.
Overall, I’d love to see more concrete motivating examples, but expect to oppose the PEP regardless on the basis that people should almost always use explicit keyword-only parameters or pass a config dict-or-object instead; and the remaining cases are insufficient to justify complicating the language for both learners and maintainers.