basedmypy
basedmypy copied to clipboard
an `UnsafeVariance` modifier
class A(Generic[T_co]):
def foo(self, t: T_co):
print(t)
This code is 100% type safe, the usage of t is safe. It would be nice if there was a form of generic where safe usages can be guaranteed, a stop gap would be to introduce an UnsafeVariance modifier that just allows these usages.
def foo(self, t: UnsafeVariance[T_co]):
egg
class A[out T]:
def foo(self, t: UnsafeVariance[T]):
reveal_type(t) # object
a = A[int]
a.foo("") # error, expected int, found str
Related: #62