From 4c4d56098382c4215c1f5af0aa9f67e32e380a4d Mon Sep 17 00:00:00 2001 From: George Ogden Date: Fri, 27 Feb 2026 13:56:11 +0000 Subject: [PATCH] Add typeguards to __contains__ methods --- stdlib/typing.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index af1d1650da41..daa236f84cb5 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -665,7 +665,7 @@ class Sequence(Reversible[_T_co], Collection[_T_co]): # Mixin methods def index(self, value: Any, start: int = 0, stop: int = ..., /) -> int: ... def count(self, value: Any, /) -> int: ... - def __contains__(self, value: object, /) -> bool: ... + def __contains__(self, value: object, /) -> TypeGuard[_T_co]: ... def __iter__(self) -> Iterator[_T_co]: ... def __reversed__(self) -> Iterator[_T_co]: ... @@ -791,7 +791,7 @@ class Mapping(Collection[_KT], Generic[_KT, _VT_co]): def items(self) -> ItemsView[_KT, _VT_co]: ... def keys(self) -> KeysView[_KT]: ... def values(self) -> ValuesView[_VT_co]: ... - def __contains__(self, key: object, /) -> bool: ... + def __contains__(self, key: object, /) -> TypeGuard[_KT]: ... def __eq__(self, other: object, /) -> bool: ... class MutableMapping(Mapping[_KT, _VT]):