Refactor round and add tests (#9151)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
Nikita Sobolev
2022-11-11 21:19:51 +03:00
committed by GitHub
parent 9f80dbd3db
commit 70c4af4b73
2 changed files with 83 additions and 5 deletions

View File

@@ -50,7 +50,6 @@ from typing import ( # noqa: Y027
SupportsComplex,
SupportsFloat,
SupportsInt,
SupportsRound,
TypeVar,
overload,
type_check_only,
@@ -1619,12 +1618,21 @@ class reversed(Iterator[_T], Generic[_T]):
def __length_hint__(self) -> int: ...
def repr(__obj: object) -> str: ...
# See https://github.com/python/typeshed/pull/9141
# and https://github.com/python/typeshed/pull/9151
# on why we don't use `SupportsRound` from `typing.pyi`
class _SupportsRound1(Protocol[_T_co]):
def __round__(self) -> _T_co: ...
class _SupportsRound2(Protocol[_T_co]):
def __round__(self, __ndigits: int) -> _T_co: ...
@overload
def round(number: SupportsRound[Any]) -> int: ...
def round(number: _SupportsRound1[_T], ndigits: None = ...) -> _T: ...
@overload
def round(number: SupportsRound[Any], ndigits: None) -> int: ...
@overload
def round(number: SupportsRound[_T], ndigits: SupportsIndex) -> _T: ...
def round(number: _SupportsRound2[_T], ndigits: SupportsIndex) -> _T: ...
# See https://github.com/python/typeshed/pull/6292#discussion_r748875189
# for why arg 3 of `setattr` should be annotated with `Any` and not `object`