Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions stdlib/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ _S = TypeVar("_S")
_KT = TypeVar("_KT") # Key type.
_VT = TypeVar("_VT") # Value type.
_T_co = TypeVar("_T_co", covariant=True) # Any type covariant containers.
_T_contra = TypeVar("_T_contra", contravariant=True) # Any type contravariant containers.
Comment thread
randolf-scholz marked this conversation as resolved.
Outdated
_KT_co = TypeVar("_KT_co", covariant=True) # Key type covariant containers.
_VT_co = TypeVar("_VT_co", covariant=True) # Value type covariant containers.
_TC = TypeVar("_TC", bound=type[object])
Expand Down Expand Up @@ -641,13 +642,13 @@ class AsyncGenerator(AsyncIterator[_YieldT_co], Protocol[_YieldT_co, _SendT_cont
def aclose(self) -> Coroutine[Any, Any, None]: ...

@runtime_checkable
class Container(Protocol[_T_co]):
# This is generic more on vibes than anything else
Comment thread
randolf-scholz marked this conversation as resolved.
class Container(Protocol[_T_contra]):
@abstractmethod
def __contains__(self, x: object, /) -> bool: ...
def __contains__(self, x: _T_contra, /) -> bool: ...

@runtime_checkable
class Collection(Iterable[_T_co], Container[_T_co], Protocol[_T_co]):
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: ...
Expand Down
Loading