Skip to content

Commit

Permalink
introduce SupportsBool
Browse files Browse the repository at this point in the history
  • Loading branch information
randolf-scholz committed Aug 21, 2024
1 parent 8307b3c commit 0246c59
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions stdlib/_typeshed/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ MaybeNone: TypeAlias = Any # stable
# def foo(x: int | None | _SentinelType = ...) -> None: ...
sentinel: Any

class SupportsBool(Protocol):
def __bool__(self) -> bool: ...

# stable
class IdentityFunction(Protocol):
def __call__(self, x: _T, /) -> _T: ...
Expand All @@ -85,16 +88,16 @@ class SupportsAnext(Protocol[_T_co]):
# Comparison protocols

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

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

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

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

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

# stable
class SupportsContainsAndGetItem(Protocol[_KT_contra, _VT_co]):
def __contains__(self, x: Any, /) -> bool: ...
def __contains__(self, x: Any, /) -> SupportsBool: ...
def __getitem__(self, key: _KT_contra, /) -> _VT_co: ...

# stable
class SupportsItemAccess(Protocol[_KT_contra, _VT]):
def __contains__(self, x: Any, /) -> bool: ...
def __contains__(self, x: Any, /) -> SupportsBool: ...
def __getitem__(self, key: _KT_contra, /) -> _VT: ...
def __setitem__(self, key: _KT_contra, value: _VT, /) -> None: ...
def __delitem__(self, key: _KT_contra, /) -> None: ...
Expand Down Expand Up @@ -287,7 +290,7 @@ class IndexableBuffer(Buffer, Protocol):
def __getitem__(self, i: int, /) -> int: ...

class SupportsGetItemBuffer(SliceableBuffer, IndexableBuffer, Protocol):
def __contains__(self, x: Any, /) -> bool: ...
def __contains__(self, x: Any, /) -> SupportsBool: ...
@overload
def __getitem__(self, slice: slice, /) -> Sequence[int]: ...
@overload
Expand Down

0 comments on commit 0246c59

Please sign in to comment.