From 3a16ebb46313090ad665d06de1741560297cc608 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Wed, 14 Oct 2020 00:47:47 -0700 Subject: [PATCH] builtins: int can accept __trunc__-able (#4665) Refer to https://docs.python.org/3/reference/datamodel.html#object.__trunc__ Fixes https://github.com/python/mypy/issues/9588 Co-authored-by: hauntsaninja <> --- 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 403bed0cb..da882b108 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 403bed0cb..da882b108 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):