Skip to content
Closed
Changes from all 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
11 changes: 8 additions & 3 deletions stdlib/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,14 @@ class AsyncGenerator(AsyncIterator[_YieldT_co], Protocol[_YieldT_co, _SendT_cont

@runtime_checkable
class Container(Protocol[_T_co]):
# This is generic more on vibes than anything else
@abstractmethod
def __contains__(self, x: object, /) -> bool: ...
# This Protocol is broken, as it should have used a contravariant type variable.
# But since it has been used in contravariant types, we cannot change it without
# causing breakage.
# Therefore, the key is annotated as `Any`, so that implemented can override it
# appropriately.
# A typical usage in Collection[X] types may be to set it to the upper bound of X.
@abstractmethod
def __contains__(self, x: Any, /) -> bool: ...

@runtime_checkable
class Collection(Iterable[_T_co], Container[_T_co], Protocol[_T_co]):
Expand Down