From 468545c7254959ceaab21cba79df2751c2131883 Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Tue, 13 Oct 2020 14:42:34 -0700 Subject: [PATCH] builtins: int can accept __trunc__-able Refer to https://docs.python.org/3/reference/datamodel.html#object.__trunc__ Fixes https://github.com/python/mypy/issues/9588 --- stdlib/2/__builtin__.pyi | 5 ++++- stdlib/2and3/builtins.pyi | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 403bed0cbc91..da882b108605 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -69,6 +69,9 @@ if sys.version_info >= (3, 9): class _SupportsIndex(Protocol): def __index__(self) -> int: ... +class _SupportsTrunc(Protocol): + def __trunc__(self) -> int: ... + class _SupportsLessThan(Protocol): def __lt__(self, __other: Any) -> bool: ... @@ -182,7 +185,7 @@ class super(object): class int: @overload - def __new__(cls: Type[_T], x: Union[Text, bytes, SupportsInt, _SupportsIndex] = ...) -> _T: ... + def __new__(cls: Type[_T], x: Union[Text, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc] = ...) -> _T: ... @overload def __new__(cls: Type[_T], x: Union[Text, bytes, bytearray], base: int) -> _T: ... if sys.version_info >= (3, 8): diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index 403bed0cbc91..da882b108605 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -69,6 +69,9 @@ if sys.version_info >= (3, 9): class _SupportsIndex(Protocol): def __index__(self) -> int: ... +class _SupportsTrunc(Protocol): + def __trunc__(self) -> int: ... + class _SupportsLessThan(Protocol): def __lt__(self, __other: Any) -> bool: ... @@ -182,7 +185,7 @@ class super(object): class int: @overload - def __new__(cls: Type[_T], x: Union[Text, bytes, SupportsInt, _SupportsIndex] = ...) -> _T: ... + def __new__(cls: Type[_T], x: Union[Text, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc] = ...) -> _T: ... @overload def __new__(cls: Type[_T], x: Union[Text, bytes, bytearray], base: int) -> _T: ... if sys.version_info >= (3, 8):