mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-09 05:24:52 +08:00
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:
@@ -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`
|
||||
|
||||
Reference in New Issue
Block a user