Skip to content

How to specify ParamSpec signature in assert_type? #1465

Answered by Daverball
randolf-scholz asked this question in Q&A
Discussion options

You must be logged in to vote

The point of assert_type is to be as strict as possible and only allow exact matches, your first statement already sort of does the check you want to make, since a static type checker would complain if the signature wasn't compatible with the positional only version.

I agree that it would be nice to have a way to specify all the different kinds of arguments in a ParamSpec and mypy has an old unsupported representation of those arguments, however it will not allow them to be used in ParamSpec, even if it still sort of generates them and uses them internally.

I think the following is perfectly fine for testing what you wanted to test. It won't catch Any, so it's not a perfect replacement for

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Daverball
Comment options

Answer selected by randolf-scholz
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