class A[out T]:
def foo(self, t: UnsafeVariance[T]):
reveal_type(t) # object
a = A[int]
a.foo("") # error, expected int, found str
use case:
class ImmutableList[out T]:
data: list[object]
def __contains__(self, it: UnsafeVariance[T]) -> bool:
return it in self.data # pretty much the only thing you're allowed to do with it
this would allow us to create a better Mapping type with a covariant key type: #268
use case:
this would allow us to create a better
Mapping
type with a covariant key type: #268