diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 5695b17ca36d..303afce20888 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -629,7 +629,7 @@ class str(Sequence[str]): @overload def __add__(self, value: str, /) -> str: ... # type: ignore[misc] # Incompatible with Sequence.__contains__ - def __contains__(self, key: str, /) -> bool: ... # type: ignore[override] + def __contains__(self, key: str, /) -> TypeGuard[str]: ... # type: ignore[override] def __eq__(self, value: object, /) -> bool: ... def __ge__(self, value: str, /) -> bool: ... @overload @@ -1162,7 +1162,7 @@ class list(MutableSequence[_T]): def __mul__(self, value: SupportsIndex, /) -> list[_T]: ... def __rmul__(self, value: SupportsIndex, /) -> list[_T]: ... def __imul__(self, value: SupportsIndex, /) -> Self: ... - def __contains__(self, key: object, /) -> bool: ... + def __contains__(self, key: object, /) -> TypeGuard[_T]: ... def __reversed__(self) -> Iterator[_T]: ... def __gt__(self, value: list[_T], /) -> bool: ... def __ge__(self, value: list[_T], /) -> bool: ... @@ -1276,7 +1276,7 @@ class set(MutableSet[_T]): def union(self, *s: Iterable[_S]) -> set[_T | _S]: ... def update(self, *s: Iterable[_T]) -> None: ... def __len__(self) -> int: ... - def __contains__(self, o: object, /) -> bool: ... + def __contains__(self, o: object, /) -> TypeGuard[_T]: ... def __iter__(self) -> Iterator[_T]: ... def __and__(self, value: AbstractSet[object], /) -> set[_T]: ... def __iand__(self, value: AbstractSet[object], /) -> Self: ... @@ -1309,7 +1309,7 @@ class frozenset(AbstractSet[_T_co]): def symmetric_difference(self, s: Iterable[_T_co], /) -> frozenset[_T_co]: ... def union(self, *s: Iterable[_S]) -> frozenset[_T_co | _S]: ... def __len__(self) -> int: ... - def __contains__(self, o: object, /) -> bool: ... + def __contains__(self, o: object, /) -> TypeGuard[_T_co]: ... def __iter__(self) -> Iterator[_T_co]: ... def __and__(self, value: AbstractSet[_T_co], /) -> frozenset[_T_co]: ... def __or__(self, value: AbstractSet[_S], /) -> frozenset[_T_co | _S]: ... diff --git a/stdlib/unittest/mock.pyi b/stdlib/unittest/mock.pyi index ef51d721297a..a6721b5dca4c 100644 --- a/stdlib/unittest/mock.pyi +++ b/stdlib/unittest/mock.pyi @@ -4,7 +4,7 @@ from collections.abc import Awaitable, Callable, Coroutine, Iterable, Mapping, S from contextlib import _GeneratorContextManager from types import TracebackType from typing import Any, ClassVar, Final, Generic, Literal, TypeVar, overload, type_check_only -from typing_extensions import ParamSpec, Self, TypeAlias, disjoint_base +from typing_extensions import ParamSpec, Self, TypeAlias, TypeGuard, disjoint_base _T = TypeVar("_T") _TT = TypeVar("_TT", bound=type[Any]) @@ -132,7 +132,7 @@ else: call: _Call class _CallList(list[_Call]): - def __contains__(self, value: Any) -> bool: ... + def __contains__(self, value: Any) -> TypeGuard[_Call]: ... class Base: def __init__(self, *args: Any, **kwargs: Any) -> None: ...