Skip to content

Commit 0e39239

Browse files
committed
Add typeguards to builtins contains
1 parent a5633e3 commit 0e39239

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

stdlib/builtins.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ class str(Sequence[str]):
629629
@overload
630630
def __add__(self, value: str, /) -> str: ... # type: ignore[misc]
631631
# Incompatible with Sequence.__contains__
632-
def __contains__(self, key: str, /) -> bool: ... # type: ignore[override]
632+
def __contains__(self, key: str, /) -> TypeGuard[str]: ... # type: ignore[override]
633633
def __eq__(self, value: object, /) -> bool: ...
634634
def __ge__(self, value: str, /) -> bool: ...
635635
@overload
@@ -1162,7 +1162,7 @@ class list(MutableSequence[_T]):
11621162
def __mul__(self, value: SupportsIndex, /) -> list[_T]: ...
11631163
def __rmul__(self, value: SupportsIndex, /) -> list[_T]: ...
11641164
def __imul__(self, value: SupportsIndex, /) -> Self: ...
1165-
def __contains__(self, key: object, /) -> bool: ...
1165+
def __contains__(self, key: object, /) -> TypeGuard[_T]: ...
11661166
def __reversed__(self) -> Iterator[_T]: ...
11671167
def __gt__(self, value: list[_T], /) -> bool: ...
11681168
def __ge__(self, value: list[_T], /) -> bool: ...
@@ -1276,7 +1276,7 @@ class set(MutableSet[_T]):
12761276
def union(self, *s: Iterable[_S]) -> set[_T | _S]: ...
12771277
def update(self, *s: Iterable[_T]) -> None: ...
12781278
def __len__(self) -> int: ...
1279-
def __contains__(self, o: object, /) -> bool: ...
1279+
def __contains__(self, o: object, /) -> TypeGuard[_T]: ...
12801280
def __iter__(self) -> Iterator[_T]: ...
12811281
def __and__(self, value: AbstractSet[object], /) -> set[_T]: ...
12821282
def __iand__(self, value: AbstractSet[object], /) -> Self: ...
@@ -1309,7 +1309,7 @@ class frozenset(AbstractSet[_T_co]):
13091309
def symmetric_difference(self, s: Iterable[_T_co], /) -> frozenset[_T_co]: ...
13101310
def union(self, *s: Iterable[_S]) -> frozenset[_T_co | _S]: ...
13111311
def __len__(self) -> int: ...
1312-
def __contains__(self, o: object, /) -> bool: ...
1312+
def __contains__(self, o: object, /) -> TypeGuard[_T_co]: ...
13131313
def __iter__(self) -> Iterator[_T_co]: ...
13141314
def __and__(self, value: AbstractSet[_T_co], /) -> frozenset[_T_co]: ...
13151315
def __or__(self, value: AbstractSet[_S], /) -> frozenset[_T_co | _S]: ...

stdlib/unittest/mock.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from collections.abc import Awaitable, Callable, Coroutine, Iterable, Mapping, S
44
from contextlib import _GeneratorContextManager
55
from types import TracebackType
66
from typing import Any, ClassVar, Final, Generic, Literal, TypeVar, overload, type_check_only
7-
from typing_extensions import ParamSpec, Self, TypeAlias, disjoint_base
7+
from typing_extensions import ParamSpec, Self, TypeAlias, TypeGuard, disjoint_base
88

99
_T = TypeVar("_T")
1010
_TT = TypeVar("_TT", bound=type[Any])
@@ -132,7 +132,7 @@ else:
132132
call: _Call
133133

134134
class _CallList(list[_Call]):
135-
def __contains__(self, value: Any) -> bool: ...
135+
def __contains__(self, value: Any) -> TypeGuard[_Call]: ...
136136

137137
class Base:
138138
def __init__(self, *args: Any, **kwargs: Any) -> None: ...

0 commit comments

Comments
 (0)