Added missing type annotations for fractions and numbers modules. (#4401)

Co-authored-by: Eric Traut <erictr@microsoft.com>
This commit is contained in:
Eric Traut
2020-08-15 18:28:14 -07:00
committed by GitHub
parent 8059ea72f8
commit 002a444dff
2 changed files with 144 additions and 64 deletions

View File

@@ -7,7 +7,8 @@
import sys
from decimal import Decimal
from numbers import Integral, Rational, Real
from typing import Any, Optional, Tuple, Union, overload
from typing import Optional, Tuple, Union, overload
from typing_extensions import Literal
_ComparableNum = Union[int, float, Decimal, Real]
@@ -39,25 +40,101 @@ class Fraction(Rational):
def numerator(self) -> int: ...
@property
def denominator(self) -> int: ...
def __add__(self, other): ...
def __radd__(self, other): ...
def __sub__(self, other): ...
def __rsub__(self, other): ...
def __mul__(self, other): ...
def __rmul__(self, other): ...
def __truediv__(self, other): ...
def __rtruediv__(self, other): ...
@overload
def __add__(self, other: Union[int, Fraction]) -> Fraction: ...
@overload
def __add__(self, other: float) -> float: ...
@overload
def __add__(self, other: complex) -> complex: ...
@overload
def __radd__(self, other: Union[int, Fraction]) -> Fraction: ...
@overload
def __radd__(self, other: float) -> float: ...
@overload
def __radd__(self, other: complex) -> complex: ...
@overload
def __sub__(self, other: Union[int, Fraction]) -> Fraction: ...
@overload
def __sub__(self, other: float) -> float: ...
@overload
def __sub__(self, other: complex) -> complex: ...
@overload
def __rsub__(self, other: Union[int, Fraction]) -> Fraction: ...
@overload
def __rsub__(self, other: float) -> float: ...
@overload
def __rsub__(self, other: complex) -> complex: ...
@overload
def __mul__(self, other: Union[int, Fraction]) -> Fraction: ...
@overload
def __mul__(self, other: float) -> float: ...
@overload
def __mul__(self, other: complex) -> complex: ...
@overload
def __rmul__(self, other: Union[int, Fraction]) -> Fraction: ...
@overload
def __rmul__(self, other: float) -> float: ...
@overload
def __rmul__(self, other: complex) -> complex: ...
@overload
def __truediv__(self, other: Union[int, Fraction]) -> Fraction: ...
@overload
def __truediv__(self, other: float) -> float: ...
@overload
def __truediv__(self, other: complex) -> complex: ...
@overload
def __rtruediv__(self, other: Union[int, Fraction]) -> Fraction: ...
@overload
def __rtruediv__(self, other: float) -> float: ...
@overload
def __rtruediv__(self, other: complex) -> complex: ...
if sys.version_info < (3, 0):
def __div__(self, other): ...
def __rdiv__(self, other): ...
def __floordiv__(self, other) -> int: ...
def __rfloordiv__(self, other) -> int: ...
def __mod__(self, other): ...
def __rmod__(self, other): ...
def __divmod__(self, other): ...
def __rdivmod__(self, other): ...
def __pow__(self, other): ...
def __rpow__(self, other): ...
@overload
def __div__(self, other: Union[int, Fraction]) -> Fraction: ...
@overload
def __div__(self, other: float) -> float: ...
@overload
def __div__(self, other: complex) -> complex: ...
@overload
def __rdiv__(self, other: Union[int, Fraction]) -> Fraction: ...
@overload
def __rdiv__(self, other: float) -> float: ...
@overload
def __rdiv__(self, other: complex) -> complex: ...
@overload
def __floordiv__(self, other: Union[int, Fraction]) -> int: ...
@overload
def __floordiv__(self, other: float) -> float: ...
@overload
def __rfloordiv__(self, other: Union[int, Fraction]) -> int: ...
@overload
def __rfloordiv__(self, other: float) -> float: ...
@overload
def __mod__(self, other: Union[int, Fraction]) -> Fraction: ...
@overload
def __mod__(self, other: float) -> float: ...
@overload
def __rmod__(self, other: Union[int, Fraction]) -> Fraction: ...
@overload
def __rmod__(self, other: float) -> float: ...
@overload
def __divmod__(self, other: Union[int, Fraction]) -> Tuple[int, Fraction]: ...
@overload
def __divmod__(self, other: float) -> Tuple[float, Fraction]: ...
@overload
def __rdivmod__(self, other: Union[int, Fraction]) -> Tuple[int, Fraction]: ...
@overload
def __rdivmod__(self, other: float) -> Tuple[float, Fraction]: ...
@overload
def __pow__(self, other: int) -> Fraction: ...
@overload
def __pow__(self, other: Union[float, Fraction]) -> float: ...
@overload
def __pow__(self, other: complex) -> complex: ...
@overload
def __rpow__(self, other: Union[int, float, Fraction]) -> float: ...
@overload
def __rpow__(self, other: complex) -> complex: ...
def __pos__(self) -> Fraction: ...
def __neg__(self) -> Fraction: ...
def __abs__(self) -> Fraction: ...
@@ -65,7 +142,10 @@ class Fraction(Rational):
if sys.version_info >= (3, 0):
def __floor__(self) -> int: ...
def __ceil__(self) -> int: ...
def __round__(self, ndigits: Optional[Any] = ...): ...
@overload
def __round__(self, ndigits: int) -> Fraction: ...
@overload
def __round__(self, ndigits: None = ...) -> int: ...
def __hash__(self) -> int: ...
def __eq__(self, other: object) -> bool: ...
def __lt__(self, other: _ComparableNum) -> bool: ...
@@ -81,5 +161,5 @@ class Fraction(Rational):
@property
def real(self) -> Fraction: ...
@property
def imag(self) -> Fraction: ...
def imag(self) -> Literal[0]: ...
def conjugate(self) -> Fraction: ...