Skip to content

Static type assertions for testing #1030

Answered by graingert
whitphx asked this question in Q&A
Discussion options

You must be logged in to vote

For those coming to this discussion mypy now has native support for assert_type https://mypy.readthedocs.io/en/stable/error_code_list.html#check-types-in-assert-type-assert-type

from typing_extensions import assert_type

assert_type([1], list[int])  # OK

assert_type([1], list[str])  # Error

Replies: 6 comments 20 replies

Comment options

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

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
7 replies
@whitphx
Comment options

@erictraut
Comment options

@whitphx
Comment options

@JelleZijlstra
Comment options

@thejcannon
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
9 replies
@sobolevn
Comment options

@JelleZijlstra
Comment options

@AlexWaygood
Comment options

@whitphx
Comment options

@Viicos
Comment options

Comment options

You must be logged in to vote
3 replies
@whitphx
Comment options

@graingert
Comment options

@whitphx
Comment options

Answer selected by whitphx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet