Skip to content

Commit 53675b6

Browse files
use 'Any' rather than object in Container
1 parent 8a363f6 commit 53675b6

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

stdlib/typing.pyi

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -642,9 +642,14 @@ class AsyncGenerator(AsyncIterator[_YieldT_co], Protocol[_YieldT_co, _SendT_cont
642642

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

649654
@runtime_checkable
650655
class Collection(Iterable[_T_co], Container[_T_co], Protocol[_T_co]):

0 commit comments

Comments
 (0)