basedmypy
basedmypy copied to clipboard
Make a `SafeVariance` annotation modifier
class Base(Generic[T_co]):
def foo(t: SafeVariance[T_co]):
reveal_type(t) # SafeVariance[T_co] effective 'object'
class InvariantDerived(Base[T_co]):
def foo(t: Invariant[T_co]): ...
reveal_type(t) # Invariant[T_co]
class CovariantDerived(Base[T_co]):
def foo(t: SafeVariance[T_co]): ...
b1: Base[object] = InvariantDerived[int] # error
b2: Base[object] = CovariantDerived[int] # no error
This will be very helpful in all sorts of scenarios, such as Mappings key type
I think SafeVariance would be really good for tracking safe usage of variance (#224), so what if MaybeVariance instead?
On the other hand, maybe these are the same issue 🤔.