From a4059c24d9ce8fe2c3fa60c010d9c932cf6926c1 Mon Sep 17 00:00:00 2001 From: Randolf Scholz Date: Fri, 1 Nov 2024 14:19:33 +0100 Subject: [PATCH 1/2] added SupportsBool --- stdlib/_typeshed/__init__.pyi | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/stdlib/_typeshed/__init__.pyi b/stdlib/_typeshed/__init__.pyi index 7201819b25ed..fa6678289347 100644 --- a/stdlib/_typeshed/__init__.pyi +++ b/stdlib/_typeshed/__init__.pyi @@ -82,19 +82,22 @@ class SupportsNext(Protocol[_T_co]): class SupportsAnext(Protocol[_T_co]): def __anext__(self) -> Awaitable[_T_co]: ... +class SupportsBool(Protocol): + def __bool__(self) -> bool: ... + # 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 From ac2cabd05d008ccc1fa09b9d5fb276a96fc2f5a7 Mon Sep 17 00:00:00 2001 From: Randolf Scholz Date: Fri, 1 Nov 2024 14:46:59 +0100 Subject: [PATCH 2/2] bool.__new__ constructors --- stdlib/builtins.pyi | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 2fea1b29a434..6d0b0ef612cc 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -19,6 +19,7 @@ from _typeshed import ( SupportsAdd, SupportsAiter, SupportsAnext, + SupportsBool, SupportsDivMod, SupportsFlush, SupportsIter, @@ -908,7 +909,12 @@ class memoryview(Sequence[_I]): @final class bool(int): - def __new__(cls, o: object = ..., /) -> Self: ... + @overload + def __new__(cls) -> Literal[False]: ... + @overload + def __new__(cls, o: SupportsBool | Sized, /) -> bool: ... + @overload + def __new__(cls, o: object, /) -> Literal[True]: ... # The following overloads could be represented more elegantly with a TypeVar("_B", bool, int), # however mypy has a bug regarding TypeVar constraints (https://github.com/python/mypy/issues/11880). @overload