Format: application/octet-stream
1 import sys
2 from decimal import Decimal
3 from numbers import Integral, Rational, Real
4 from typing import Optional, Tuple, Union, overload
5 from typing_extensions import Literal
6
7 _ComparableNum = Union[int, float, Decimal, Real]
8
9 if sys.version_info < (3, 9):
10 @overload
11 def gcd(a: int, b: int) -> int: ...
12 @overload
13 def gcd(a: Integral, b: int) -> Integral: ...
14 @overload
15 def gcd(a: int, b: Integral) -> Integral: ...
16 @overload
17 def gcd(a: Integral, b: Integral) -> Integral: ...
18
19 class Fraction(Rational):
20 @overload
21 def __new__(
22 cls, numerator: Union[int, Rational] = ..., denominator: Optional[Union[int, Rational]] = ..., *, _normalize: bool = ...
23 ) -> Fraction: ...
24 @overload
25 def __new__(cls, __value: Union[float, Decimal, str], *, _normalize: bool = ...) -> Fraction: ...
26 @classmethod
27 def from_float(cls, f: float) -> Fraction: ...
28 @classmethod
29 def from_decimal(cls, dec: Decimal) -> Fraction: ...
30 def limit_denominator(self, max_denominator: int = ...) -> Fraction: ...
31 if sys.version_info >= (3, 8):
32 def as_integer_ratio(self) -> Tuple[int, int]: ...
33 @property
34 def numerator(self) -> int: ...
35 @property
36 def denominator(self) -> int: ...
37 @overload
38 def __add__(self, other: Union[int, Fraction]) -> Fraction: ...
39 @overload
40 def __add__(self, other: float) -> float: ...
41 @overload
42 def __add__(self, other: complex) -> complex: ...
43 @overload
44 def __radd__(self, other: Union[int, Fraction]) -> Fraction: ...
45 @overload
46 def __radd__(self, other: float) -> float: ...
47 @overload
48 def __radd__(self, other: complex) -> complex: ...
49 @overload
50 def __sub__(self, other: Union[int, Fraction]) -> Fraction: ...
51 @overload
52 def __sub__(self, other: float) -> float: ...
53 @overload
54 def __sub__(self, other: complex) -> complex: ...
55 @overload
56 def __rsub__(self, other: Union[int, Fraction]) -> Fraction: ...
57 @overload
58 def __rsub__(self, other: float) -> float: ...
59 @overload
60 def __rsub__(self, other: complex) -> complex: ...
61 @overload
62 def __mul__(self, other: Union[int, Fraction]) -> Fraction: ...
63 @overload
64 def __mul__(self, other: float) -> float: ...
65 @overload
66 def __mul__(self, other: complex) -> complex: ...
67 @overload
68 def __rmul__(self, other: Union[int, Fraction]) -> Fraction: ...
69 @overload
70 def __rmul__(self, other: float) -> float: ...
71 @overload
72 def __rmul__(self, other: complex) -> complex: ...
73 @overload
74 def __truediv__(self, other: Union[int, Fraction]) -> Fraction: ...
75 @overload
76 def __truediv__(self, other: float) -> float: ...
77 @overload
78 def __truediv__(self, other: complex) -> complex: ...
79 @overload
80 def __rtruediv__(self, other: Union[int, Fraction]) -> Fraction: ...
81 @overload
82 def __rtruediv__(self, other: float) -> float: ...
83 @overload
84 def __rtruediv__(self, other: complex) -> complex: ...
85 if sys.version_info < (3, 0):
86 @overload
87 def __div__(self, other: Union[int, Fraction]) -> Fraction: ...
88 @overload
89 def __div__(self, other: float) -> float: ...
90 @overload
91 def __div__(self, other: complex) -> complex: ...
92 @overload
93 def __rdiv__(self, other: Union[int, Fraction]) -> Fraction: ...
94 @overload
95 def __rdiv__(self, other: float) -> float: ...
96 @overload
97 def __rdiv__(self, other: complex) -> complex: ...
98 @overload
99 def __floordiv__(self, other: Union[int, Fraction]) -> int: ...
100 @overload
101 def __floordiv__(self, other: float) -> float: ...
102 @overload
103 def __rfloordiv__(self, other: Union[int, Fraction]) -> int: ...
104 @overload
105 def __rfloordiv__(self, other: float) -> float: ...
106 @overload
107 def __mod__(self, other: Union[int, Fraction]) -> Fraction: ...
108 @overload
109 def __mod__(self, other: float) -> float: ...
110 @overload
111 def __rmod__(self, other: Union[int, Fraction]) -> Fraction: ...
112 @overload
113 def __rmod__(self, other: float) -> float: ...
114 @overload
115 def __divmod__(self, other: Union[int, Fraction]) -> Tuple[int, Fraction]: ...
116 @overload
117 def __divmod__(self, other: float) -> Tuple[float, Fraction]: ...
118 @overload
119 def __rdivmod__(self, other: Union[int, Fraction]) -> Tuple[int, Fraction]: ...
120 @overload
121 def __rdivmod__(self, other: float) -> Tuple[float, Fraction]: ...
122 @overload
123 def __pow__(self, other: int) -> Fraction: ...
124 @overload
125 def __pow__(self, other: Union[float, Fraction]) -> float: ...
126 @overload
127 def __pow__(self, other: complex) -> complex: ...
128 @overload
129 def __rpow__(self, other: Union[int, float, Fraction]) -> float: ...
130 @overload
131 def __rpow__(self, other: complex) -> complex: ...
132 def __pos__(self) -> Fraction: ...
133 def __neg__(self) -> Fraction: ...
134 def __abs__(self) -> Fraction: ...
135 def __trunc__(self) -> int: ...
136 if sys.version_info >= (3, 0):
137 def __floor__(self) -> int: ...
138 def __ceil__(self) -> int: ...
139 @overload
140 def __round__(self, ndigits: None = ...) -> int: ...
141 @overload
142 def __round__(self, ndigits: int) -> Fraction: ...
143 def __hash__(self) -> int: ...
144 def __eq__(self, other: object) -> bool: ...
145 def __lt__(self, other: _ComparableNum) -> bool: ...
146 def __gt__(self, other: _ComparableNum) -> bool: ...
147 def __le__(self, other: _ComparableNum) -> bool: ...
148 def __ge__(self, other: _ComparableNum) -> bool: ...
149 if sys.version_info >= (3, 0):
150 def __bool__(self) -> bool: ...
151 else:
152 def __nonzero__(self) -> bool: ...
153 # Not actually defined within fractions.py, but provides more useful
154 # overrides
155 @property
156 def real(self) -> Fraction: ...
157 @property
158 def imag(self) -> Literal[0]: ...
159 def conjugate(self) -> Fraction: ...
160