Skip to content

Is typing.Protocol the only way to concatenate the keyword-only arguments in ParamSpec? #1905

Answered by Daverball
McDic asked this question in Q&A
Discussion options

You must be logged in to vote

There's no way to do this currently, even the Protocol way doesn't work and pyright is correct to complain. You are only allowed prepend positional only parameters using typing.Concatenate and *args: P.args must always be directly followed by **kwargs: P.kwargs in a signature.

You can perform slightly more complex parameter list extensions using TypeVarTuple, but this is once again only useful for positional-only arguments.

This was a deliberate design choice of PEP-612 to keep the scope of the change smaller and easier to understand and implement. Even with the simplification it proved to be one of the most challenging changes for type checkers to implement. It took quite a while for sup…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by McDic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants