mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-06-23 17:28:38 +08:00
Use contravariant type variable rather than object in Container (#15320)
This commit is contained in:
+9
-6
@@ -640,14 +640,17 @@ class AsyncGenerator(AsyncIterator[_YieldT_co], Protocol[_YieldT_co, _SendT_cont
|
||||
) -> Coroutine[Any, Any, _YieldT_co]: ...
|
||||
def aclose(self) -> Coroutine[Any, Any, None]: ...
|
||||
|
||||
@runtime_checkable
|
||||
class Container(Protocol[_T_co]):
|
||||
# This is generic more on vibes than anything else
|
||||
@abstractmethod
|
||||
def __contains__(self, x: object, /) -> bool: ...
|
||||
_ContainerT_contra = TypeVar("_ContainerT_contra", contravariant=True, default=Any)
|
||||
|
||||
@runtime_checkable
|
||||
class Collection(Iterable[_T_co], Container[_T_co], Protocol[_T_co]):
|
||||
class Container(Protocol[_ContainerT_contra]):
|
||||
# This is generic more on vibes than anything else
|
||||
@abstractmethod
|
||||
def __contains__(self, x: _ContainerT_contra, /) -> bool: ...
|
||||
|
||||
@runtime_checkable
|
||||
class Collection(Iterable[_T_co], Container[Any], Protocol[_T_co]):
|
||||
# Note: need to use Container[Any] instead of Container[_T_co] to ensure covariance.
|
||||
# Implement Sized (but don't have it as a base class).
|
||||
@abstractmethod
|
||||
def __len__(self) -> int: ...
|
||||
|
||||
Reference in New Issue
Block a user