Fix some issues with __round__ (#2907)

In python 3, add an overload for there being no digits argument
and make it return int.

In python 2, __round__ doesn't exist and SupportsRound doesn't exist
in the typing module. Use SupportsFloat for python 2 round().

Remove decimal's __round__ overload that takes None, since it doesn't exist
This commit is contained in:
Michael J. Sullivan
2019-04-09 11:45:10 -07:00
committed by GitHub
parent 50a661afed
commit 0350e9fa89
5 changed files with 13 additions and 16 deletions

View File

@@ -5,7 +5,7 @@ from typing import (
TypeVar, Iterator, Iterable, NoReturn, overload, Container,
Sequence, MutableSequence, Mapping, MutableMapping, Tuple, List, Any, Dict, Callable, Generic,
Set, AbstractSet, FrozenSet, MutableSet, Sized, Reversible, SupportsInt, SupportsFloat, SupportsAbs,
SupportsComplex, SupportsRound, IO, BinaryIO, Union,
SupportsComplex, IO, BinaryIO, Union,
ItemsView, KeysView, ValuesView, ByteString, Optional, AnyStr, Type, Text,
Protocol,
)
@@ -15,7 +15,7 @@ from types import TracebackType, CodeType
import sys
if sys.version_info >= (3,):
from typing import SupportsBytes
from typing import SupportsBytes, SupportsRound
_T = TypeVar('_T')
_T_co = TypeVar('_T_co', covariant=True)
@@ -1370,9 +1370,9 @@ else:
@overload
def round(number: float, ndigits: int) -> float: ...
@overload
def round(number: SupportsRound[_T]) -> _T: ...
def round(number: SupportsFloat) -> float: ...
@overload
def round(number: SupportsRound[_T], ndigits: int) -> _T: ...
def round(number: SupportsFloat, ndigits: int) -> float: ...
def setattr(object: Any, name: Text, value: Any) -> None: ...
if sys.version_info >= (3,):
def sorted(iterable: Iterable[_T], *,