Skip to content

Decorator taking a (covariant?) callable and returning it again #2501

Answered by erictraut
Bluenix2 asked this question in Q&A
Discussion options

You must be logged in to vote

Parameters within callables are implicitly contravariant, which is why you're seeing the error.

Think about it this way. The function test requires that the caller pass a StrSubclass instance as the first argument. But C is bound to a callback that accepts a str. If the decorator do_nothing were to call this callback with a str argument, it wouldn't satisfy the type requirements of test.

The workaround is to either change the bound type in C to accept a StrSubclass or change test to accept a str argument.

Replies: 1 comment 1 reply

Comment options

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

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