Skip to content

Does assert_type is supposed to work with Protocol? #1819

Discussion options

You must be logged in to vote

assert_type() works with protocols, but it checks for an exact match, not for assignability. To check that Concrete is assignable to MyProtocol, it is enough to do e.g. x: MyProtocol = Concrete().

There is a specification at https://typing.readthedocs.io/en/latest/spec/directives.html#assert-type but it could be made more precise.

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@rayansostenes
Comment options

@JelleZijlstra
Comment options

@maflAT
Comment options

@erictraut
Comment options

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