1 # Stubs for fractions
\r
2 # See https://docs.python.org/3/library/fractions.html
\r
4 # Note: these stubs are incomplete. The more complex type
\r
5 # signatures are currently omitted. Also see numbers.pyi.
\r
7 from typing import Optional, TypeVar, Union, overload
\r
8 from numbers import Real, Integral, Rational
\r
9 from decimal import Decimal
\r
12 _ComparableNum = Union[int, float, Decimal, Real]
\r
16 def gcd(a: int, b: int) -> int: ...
\r
18 def gcd(a: Integral, b: int) -> Integral: ...
\r
20 def gcd(a: int, b: Integral) -> Integral: ...
\r
22 def gcd(a: Integral, b: Integral) -> Integral: ...
\r
25 class Fraction(Rational):
\r
28 numerator: Union[int, Rational] = ...,
\r
29 denominator: Optional[Union[int, Rational]] = ...,
\r
31 _normalize: bool = ...) -> None: ...
\r
33 def __init__(self, value: float, *, _normalize: bool = ...) -> None: ...
\r
35 def __init__(self, value: Decimal, *, _normalize: bool = ...) -> None: ...
\r
37 def __init__(self, value: str, *, _normalize: bool = ...) -> None: ...
\r
40 def from_float(cls, f: float) -> 'Fraction': ...
\r
42 def from_decimal(cls, dec: Decimal) -> 'Fraction': ...
\r
43 def limit_denominator(self, max_denominator: int = ...) -> 'Fraction': ...
\r
46 def numerator(self) -> int: ...
\r
48 def denominator(self) -> int: ...
\r
50 def __add__(self, other): ...
\r
51 def __radd__(self, other): ...
\r
52 def __sub__(self, other): ...
\r
53 def __rsub__(self, other): ...
\r
54 def __mul__(self, other): ...
\r
55 def __rmul__(self, other): ...
\r
56 def __truediv__(self, other): ...
\r
57 def __rtruediv__(self, other): ...
\r
58 if sys.version_info < (3, 0):
\r
59 def __div__(self, other): ...
\r
60 def __rdiv__(self, other): ...
\r
61 def __floordiv__(self, other) -> int: ...
\r
62 def __rfloordiv__(self, other) -> int: ...
\r
63 def __mod__(self, other): ...
\r
64 def __rmod__(self, other): ...
\r
65 def __divmod__(self, other): ...
\r
66 def __rdivmod__(self, other): ...
\r
67 def __pow__(self, other): ...
\r
68 def __rpow__(self, other): ...
\r
70 def __pos__(self) -> 'Fraction': ...
\r
71 def __neg__(self) -> 'Fraction': ...
\r
72 def __abs__(self) -> 'Fraction': ...
\r
73 def __trunc__(self) -> int: ...
\r
74 if sys.version_info >= (3, 0):
\r
75 def __floor__(self) -> int: ...
\r
76 def __ceil__(self) -> int: ...
\r
77 def __round__(self, ndigits=None): ...
\r
79 def __hash__(self) -> int: ...
\r
80 def __eq__(self, other: object) -> bool: ...
\r
81 def __lt__(self, other: _ComparableNum) -> bool: ...
\r
82 def __gt__(self, other: _ComparableNum) -> bool: ...
\r
83 def __le__(self, other: _ComparableNum) -> bool: ...
\r
84 def __ge__(self, other: _ComparableNum) -> bool: ...
\r
85 if sys.version_info >= (3, 0):
\r
86 def __bool__(self) -> bool: ...
\r
88 def __nonzero__(self) -> bool: ...
\r
90 # Not actually defined within fractions.py, but provides more useful
\r
93 def real(self) -> 'Fraction': ...
\r
95 def imag(self) -> 'Fraction': ...
\r
96 def conjugate(self) -> 'Fraction': ...
\r