Skip to content

Commit 0246c59

Browse files
introduce SupportsBool
1 parent 8307b3c commit 0246c59

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

stdlib/_typeshed/__init__.pyi

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ MaybeNone: TypeAlias = Any # stable
7070
# def foo(x: int | None | _SentinelType = ...) -> None: ...
7171
sentinel: Any
7272

73+
class SupportsBool(Protocol):
74+
def __bool__(self) -> bool: ...
75+
7376
# stable
7477
class IdentityFunction(Protocol):
7578
def __call__(self, x: _T, /) -> _T: ...
@@ -85,16 +88,16 @@ class SupportsAnext(Protocol[_T_co]):
8588
# Comparison protocols
8689

8790
class SupportsDunderLT(Protocol[_T_contra]):
88-
def __lt__(self, other: _T_contra, /) -> bool: ...
91+
def __lt__(self, other: _T_contra, /) -> SupportsBool: ...
8992

9093
class SupportsDunderGT(Protocol[_T_contra]):
91-
def __gt__(self, other: _T_contra, /) -> bool: ...
94+
def __gt__(self, other: _T_contra, /) -> SupportsBool: ...
9295

9396
class SupportsDunderLE(Protocol[_T_contra]):
94-
def __le__(self, other: _T_contra, /) -> bool: ...
97+
def __le__(self, other: _T_contra, /) -> SupportsBool: ...
9598

9699
class SupportsDunderGE(Protocol[_T_contra]):
97-
def __ge__(self, other: _T_contra, /) -> bool: ...
100+
def __ge__(self, other: _T_contra, /) -> SupportsBool: ...
98101

99102
class SupportsAllComparisons(
100103
SupportsDunderLT[Any], SupportsDunderGT[Any], SupportsDunderLE[Any], SupportsDunderGE[Any], Protocol
@@ -155,17 +158,17 @@ class SupportsKeysAndGetItem(Protocol[_KT, _VT_co]):
155158
# instead, if you require the __contains__ method.
156159
# See https://github.com/python/typeshed/issues/11822.
157160
class SupportsGetItem(Protocol[_KT_contra, _VT_co]):
158-
def __contains__(self, x: Any, /) -> bool: ...
161+
def __contains__(self, x: Any, /) -> SupportsBool: ...
159162
def __getitem__(self, key: _KT_contra, /) -> _VT_co: ...
160163

161164
# stable
162165
class SupportsContainsAndGetItem(Protocol[_KT_contra, _VT_co]):
163-
def __contains__(self, x: Any, /) -> bool: ...
166+
def __contains__(self, x: Any, /) -> SupportsBool: ...
164167
def __getitem__(self, key: _KT_contra, /) -> _VT_co: ...
165168

166169
# stable
167170
class SupportsItemAccess(Protocol[_KT_contra, _VT]):
168-
def __contains__(self, x: Any, /) -> bool: ...
171+
def __contains__(self, x: Any, /) -> SupportsBool: ...
169172
def __getitem__(self, key: _KT_contra, /) -> _VT: ...
170173
def __setitem__(self, key: _KT_contra, value: _VT, /) -> None: ...
171174
def __delitem__(self, key: _KT_contra, /) -> None: ...
@@ -287,7 +290,7 @@ class IndexableBuffer(Buffer, Protocol):
287290
def __getitem__(self, i: int, /) -> int: ...
288291

289292
class SupportsGetItemBuffer(SliceableBuffer, IndexableBuffer, Protocol):
290-
def __contains__(self, x: Any, /) -> bool: ...
293+
def __contains__(self, x: Any, /) -> SupportsBool: ...
291294
@overload
292295
def __getitem__(self, slice: slice, /) -> Sequence[int]: ...
293296
@overload

0 commit comments

Comments
 (0)