2 from decimal import Decimal
3 from numbers import Integral, Rational, Real
4 from typing import Type, TypeVar, Union, overload
5 from typing_extensions import Literal
7 _ComparableNum = Union[int, float, Decimal, Real]
10 if sys.version_info < (3, 9):
12 def gcd(a: int, b: int) -> int: ...
14 def gcd(a: Integral, b: int) -> Integral: ...
16 def gcd(a: int, b: Integral) -> Integral: ...
18 def gcd(a: Integral, b: Integral) -> Integral: ...
20 class Fraction(Rational):
23 cls: Type[_T], numerator: int | Rational = ..., denominator: int | Rational | None = ..., *, _normalize: bool = ...
26 def __new__(cls: Type[_T], __value: float | Decimal | str, *, _normalize: bool = ...) -> _T: ...
28 def from_float(cls, f: float) -> Fraction: ...
30 def from_decimal(cls, dec: Decimal) -> Fraction: ...
31 def limit_denominator(self, max_denominator: int = ...) -> Fraction: ...
32 if sys.version_info >= (3, 8):
33 def as_integer_ratio(self) -> tuple[int, int]: ...
35 def numerator(self) -> int: ...
37 def denominator(self) -> int: ...
39 def __add__(self, other: int | Fraction) -> Fraction: ...
41 def __add__(self, other: float) -> float: ...
43 def __add__(self, other: complex) -> complex: ...
45 def __radd__(self, other: int | Fraction) -> Fraction: ...
47 def __radd__(self, other: float) -> float: ...
49 def __radd__(self, other: complex) -> complex: ...
51 def __sub__(self, other: int | Fraction) -> Fraction: ...
53 def __sub__(self, other: float) -> float: ...
55 def __sub__(self, other: complex) -> complex: ...
57 def __rsub__(self, other: int | Fraction) -> Fraction: ...
59 def __rsub__(self, other: float) -> float: ...
61 def __rsub__(self, other: complex) -> complex: ...
63 def __mul__(self, other: int | Fraction) -> Fraction: ...
65 def __mul__(self, other: float) -> float: ...
67 def __mul__(self, other: complex) -> complex: ...
69 def __rmul__(self, other: int | Fraction) -> Fraction: ...
71 def __rmul__(self, other: float) -> float: ...
73 def __rmul__(self, other: complex) -> complex: ...
75 def __truediv__(self, other: int | Fraction) -> Fraction: ...
77 def __truediv__(self, other: float) -> float: ...
79 def __truediv__(self, other: complex) -> complex: ...
81 def __rtruediv__(self, other: int | Fraction) -> Fraction: ...
83 def __rtruediv__(self, other: float) -> float: ...
85 def __rtruediv__(self, other: complex) -> complex: ...
87 def __floordiv__(self, other: int | Fraction) -> int: ...
89 def __floordiv__(self, other: float) -> float: ...
91 def __rfloordiv__(self, other: int | Fraction) -> int: ...
93 def __rfloordiv__(self, other: float) -> float: ...
95 def __mod__(self, other: int | Fraction) -> Fraction: ...
97 def __mod__(self, other: float) -> float: ...
99 def __rmod__(self, other: int | Fraction) -> Fraction: ...
101 def __rmod__(self, other: float) -> float: ...
103 def __divmod__(self, other: int | Fraction) -> tuple[int, Fraction]: ...
105 def __divmod__(self, other: float) -> tuple[float, Fraction]: ...
107 def __rdivmod__(self, other: int | Fraction) -> tuple[int, Fraction]: ...
109 def __rdivmod__(self, other: float) -> tuple[float, Fraction]: ...
111 def __pow__(self, other: int) -> Fraction: ...
113 def __pow__(self, other: float | Fraction) -> float: ...
115 def __pow__(self, other: complex) -> complex: ...
117 def __rpow__(self, other: int | float | Fraction) -> float: ...
119 def __rpow__(self, other: complex) -> complex: ...
120 def __pos__(self) -> Fraction: ...
121 def __neg__(self) -> Fraction: ...
122 def __abs__(self) -> Fraction: ...
123 def __trunc__(self) -> int: ...
124 def __floor__(self) -> int: ...
125 def __ceil__(self) -> int: ...
127 def __round__(self, ndigits: None = ...) -> int: ...
129 def __round__(self, ndigits: int) -> Fraction: ...
130 def __hash__(self) -> int: ...
131 def __eq__(self, other: object) -> bool: ...
132 def __lt__(self, other: _ComparableNum) -> bool: ...
133 def __gt__(self, other: _ComparableNum) -> bool: ...
134 def __le__(self, other: _ComparableNum) -> bool: ...
135 def __ge__(self, other: _ComparableNum) -> bool: ...
136 def __bool__(self) -> bool: ...
137 if sys.version_info >= (3, 11):
138 def __int__(self) -> int: ...
139 # Not actually defined within fractions.py, but provides more useful
142 def real(self) -> Fraction: ...
144 def imag(self) -> Literal[0]: ...
145 def conjugate(self) -> Fraction: ...