8000 Added missing type annotations for fractions and numbers modules. by erictraut · Pull Request #4401 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Aug 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Incorporated code review feedback. Did a bunch of experimentation wit…
…h Fraction objects to determine proper overloads for each magic method.
  • Loading branch information
msfterictraut committed Aug 8, 2020
commit f7d16abbe77a58c80064516914abed39238fe8ed
98 changes: 77 additions & 21 deletions stdlib/2and3/fractions.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -39,33 +40,88 @@ class Fraction(Rational):
def numerator(self) -> int: ...
@property
def denominator(self) -> int: ...
def __add__(self, other: _ComparableNum) -> Fraction: ...
def __radd__(self, other: _ComparableNum) -> Fraction: ...
def __sub__(self, other: _ComparableNum) -> Fraction: ...
def __rsub__(self, other: _ComparableNum) -> Fraction: ...
def __mul__(self, other: _ComparableNum) -> Fraction: ...
def __rmul__(self, other: _ComparableNum) -> Fraction: ...
def __truediv__(self, other: _ComparableNum) -> Fraction: ...
def __rtruediv__(self, other: _ComparableNum) -> Fraction: ...
@overload
def __add__(self, other: Union[int, Fraction]) -> Fraction: ...
@overload
def __add__(self, other: float) -> float: ...
@overload
def __radd__(self, other: Union[int, Fraction]) -> Fraction: ...
@overload
def __radd__(self, other: float) -> float: ...
@overload
def __sub__(self, other: Union[int, Fraction]) -> Fraction: ...
@overload
def __sub__(self, other: float) -> float: ...
@overload
def __rsub__(self, other: Union[int, Fraction]) -> Fraction: ...
@overload
def __rsub__(self, other: float) -> float: ...
@overload
def __mul__(self, other: Union[int, Fraction]) -> Fraction: ...
@overload
def __mul__(self, other: float) -> float: ...
@overload
def __rmul__(self, other: Union[int, Fraction]) -> Fraction: ...
@overload
def __rmul__(self, other: float) -> float: ...
@overload
def __truediv__(self, other: Union[int, Fraction]) -> Fraction: ...
@overload
def __truediv__(self, other: float) -> float: ...
@overload
def __rtruediv__(self, other: Union[int, Fraction]) -> int: ...
@overload
def __rtruediv__(self, other: float) -> float: ...
if sys.version_info < (3, 0):
def __div__(self, other): ...
def __rdiv__(self, other): ...
def __floordiv__(self, other: _ComparableNum) -> int: ...
def __rfloordiv__(self, other: _ComparableNum) -> int: ...
def __mod__(self, other: _ComparableNum) -> Fraction: ...
def __rmod__(self, other: _ComparableNum) -> Fraction: ...
def __divmod__(self, other: _ComparableNum) -> Fraction: ...
def __rdivmod__(self, other: _ComparableNum) -> Fraction: ...
def __pow__(self, other: _ComparableNum) -> Fraction: ...
def __rpow__(self, other: _ComparableNum) -> Fraction: ...
@overload
def __div__(self, other: Union[int, Fraction]) -> Fraction: ...
@overload
def __div__(self, other: float) -> float: ...
@overload
def __rdiv__(self, other: Union[int, Fraction]) -> Fraction: ...
@overload
def __rdiv__(self, other: float) -> float: ...
@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 __rpow__(self, other: Union[int, float, Fraction]) -> float: ...
def __pos__(self) -> Fraction: ...
def __neg__(self) -> Fraction: ...
def __abs__(self) -> Fraction: ...
def __trunc__(self) -> int: ...
if sys.version_info >= (3, 0):
def __floor__(self) -> int: ...
def __ceil__(self) -> int: ...
def __round__(self, ndigits: Optional[Any] = ...) -> Fraction: ...
@overload
def __round__(self) -> int: ...
@overload
def __round__(self, ndigits: int) -> Fraction: ...
def __hash__(self) -> int: ...
def __eq__(self, other: object) -> bool: ...
def __lt__(self, other: _ComparableNum) -> bool: ...
Expand All @@ -81,5 +137,5 @@ class Fraction(Rational):
@property
def real(self) -> Fraction: ...
@property
def imag(self) -> Fraction: ...
def imag(self) -> Literal[0]: ...
def conjugate(self) -> Fraction: ...
14 changes: 9 additions & 5 deletions stdlib/2and3/numbers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import sys
from abc import ABCMeta, abstractmethod
from typing import Any, Optional, SupportsFloat, Type, TypeVar
from typing import Any, Optional, SupportsFloat, TypeVar, overload

_T = TypeVar("_T")

Expand All @@ -24,10 +24,10 @@ class Complex(Number):
def __nonzero__(self) -> bool: ...
@property
@abstractmethod
def real(self: _T) -> _T: ...
def real(self) -> Real: ...
@property
@abstractmethod
def imag(self: _T) -> _T: ...
def imag(self) -> Real: ...
@abstractmethod
def __add__(self: _T, other: Any) -> _T: ...
@abstractmethod
Expand Down Expand Up @@ -55,7 +55,7 @@ class Complex(Number):
def __pow__(self: _T, exponent: Any) -> _T: ...
@abstractmethod
def __rpow__(self: _T, base: Any) -> _T: ...
def __abs__(self: _T) -> _T: ...
def __abs__(self) -> Real: ...
def conjugate(self: _T) -> _T: ...
def __eq__(self, other: Any) -> bool: ...
if sys.version_info < (3, 0):
Expand All @@ -72,7 +72,11 @@ class Real(Complex, SupportsFloat):
@abstractmethod
def __ceil__(self) -> int: ...
@abstractmethod
def __round__(self: _T, ndigits: Optional[int] = ...) -> _T: ...
@overload
def __round__(self) -> int: ...
@abstractmethod
@overload
def __round__(self: _T, ndigits: int) -> _T: ...
def __divmod__(self: _T, other: Any) -> _T: ...
def __rdivmod__(self: _T, other: Any) -> _T: ...
@abstractmethod
Expand Down
0