diff --git a/requirements-tests.txt b/requirements-tests.txt index 31c12c50bc2b..aac6873bc6da 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -1,6 +1,6 @@ # Type checkers that we test our stubs against. These should always # be pinned to a specific version to make failure reproducible. -mypy==1.18.2 +mypy @ git+https://github.com/python/mypy@6aa44da pyright==1.1.406 # Libraries used by our various scripts. diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 969d1687611c..3e72aab90fbe 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -950,9 +950,20 @@ class memoryview(Sequence[_I]): if sys.version_info >= (3, 14): def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... +class _Truthy(Protocol): + def __bool__(self) -> Literal[True]: ... + +class _Falsy(Protocol): + def __bool__(self) -> Literal[False]: ... + @final class bool(int): - def __new__(cls, o: object = False, /) -> Self: ... + @overload + def __new__(cls, o: _Truthy, /) -> Literal[True]: ... + @overload + def __new__(cls, o: _Falsy = False, /) -> Literal[False]: ... + @overload + def __new__(cls, o: object, /) -> Self: ... # 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