Skip to content
13 changes: 13 additions & 0 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -898,8 +898,21 @@ class memoryview(Sequence[int]):
def __buffer__(self, __flags: int) -> memoryview: ...
def __release_buffer__(self, __buffer: memoryview) -> None: ...

class _Truthy(Protocol):
def __bool__(self) -> Literal[True]: ...

class _Falsy(Protocol):
def __bool__(self) -> Literal[False]: ...

@final
class bool(int):
@overload
def __new__(cls) -> Literal[False]: ...
@overload
def __new__(cls, __o: _Truthy) -> Literal[True]: ...
@overload
def __new__(cls, __o: _Falsy) -> Literal[False]: ...
@overload
def __new__(cls, __o: object = ...) -> Self: ...
Comment thread
Gobot1234 marked this conversation as resolved.
Outdated
# 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).
Expand Down