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 <>
This commit is contained in:
Shantanu
2020-10-14 00:47:47 -07:00
committed by GitHub
parent 67648a7dba
commit 3a16ebb463
2 changed files with 8 additions and 2 deletions

View File

@@ -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):

View File

@@ -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):