Skip to content
Discussion options

You must be logged in to vote

Function parameters are contravariant. While Example is a subtype of HasBlockUuid, the converse isn't true.

This makes sense if you think about the decorator check_block. It says that it accepts a function that expects to receive an argument that conforms to the HasBlockUuid protocol. That means check_block would be free to call this function with any object that conforms to HasBlockUuid. But the do_something function has more stringent requirements. It requires that its first parameter is an Example instance (or subtype thereof). If the check_block were to call it with some other object that happens to conform to the HasBlockUuid protocol (but is not a subtype of Example), it could crash…

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@erictraut
Comment options

@RedRoserade
Comment options

@RedRoserade
Comment options

@erictraut
Comment options

@RedRoserade
Comment options

Answer selected by RedRoserade
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