7
7
import sys
8
8
from decimal import Decimal
9
9
from numbers import Integral , Rational , Real
10
- from typing import Any , Optional , Tuple , Union , overload
10
+ from typing import Optional , Tuple , Union , overload
11
+ from typing_extensions import Literal
11
12
12
13
_ComparableNum = Union [int , float , Decimal , Real ]
13
14
@@ -39,33 +40,112 @@ class Fraction(Rational):
39
40
def numerator (self ) -> int : ...
40
41
@property
41
42
def denominator (self ) -> int : ...
42
- def __add__ (self , other ): ...
43
- def __radd__ (self , other ): ...
44
- def __sub__ (self , other ): ...
45
- def __rsub__ (self , other ): ...
46
- def __mul__ (self , other ): ...
47
- def __rmul__ (self , other ): ...
48
- def __truediv__ (self , other ): ...
49
- def __rtruediv__ (self , other ): ...
43
+ @overload
44
+ def __add__ (self , other : Union [int , Fraction ]) -> Fraction : ...
45
+ @overload
46
+ def __add__ (self , other : float ) -> float : ...
47
+ @overload
48
+ def __add__ (self , other : complex ) -> complex : ...
49
+ @overload
50
+ def __radd__ (self , other : Union [int , Fraction ]) -> Fraction : ...
51
+ @overload
52
+ def __radd__ (self , other : float ) -> float : ...
53
+ @overload
54
+ def __radd__ (self , other : complex ) -> complex : ...
55
+ @overload
56
+ def __sub__ (self , other : Union [int , Fraction ]) -> Fraction : ...
57
+ @overload
58
+ def __sub__ (self , other : float ) -> float : ...
59
+ @overload
60
+ def __sub__ (self , other : complex ) -> complex : ...
61
+ @overload
62
+ def __rsub__ (self , other : Union [int , Fraction ]) -> Fraction : ...
63
+ @overload
64
+ def __rsub__ (self , other : float ) -> float : ...
65
+ @overload
66
+ def __rsub__ (self , other : complex ) -> complex : ...
67
+ @overload
68
+ def __mul__ (self , other : Union [int , Fraction ]) -> Fraction : ...
69
+ @overload
70
+ def __mul__ (self , other : float ) -> float : ...
71
+ @overload
72
+ def __mul__ (self , other : complex ) -> complex : ...
73
+ @overload
74
+ def __rmul__ (self , other : Union [int , Fraction ]) -> Fraction : ...
75
+ @overload
76
+ def __rmul__ (self , other : float ) -> float : ...
77
+ @overload
78
+ def __rmul__ (self , other : complex ) -> complex : ...
79
+ @overload
80
+ def __truediv__ (self , other : Union [int , Fraction ]) -> Fraction : ...
81
+ @overload
82
+ def __truediv__ (self , other : float ) -> float : ...
83
+ @overload
84
+ def __truediv__ (self , other : complex ) -> complex : ...
85
+ @overload
86
+ def __rtruediv__ (self , other : Union [int , Fraction ]) -> Fraction : ...
87
+ @overload
88
+ def __rtruediv__ (self , other : float ) -> float : ...
89
+ @overload
90
+ def __rtruediv__ (self , other : complex ) -> complex : ...
50
91
if sys .version_info < (3 , 0 ):
51
- def __div__ (self , other ): ...
52
- def __rdiv__ (self , other ): ...
53
- def __floordiv__ (self , other ) -> int : ...
54
- def __rfloordiv__ (self , other ) -> int : ...
55
- def __mod__ (self , other ): ...
56
- def __rmod__ (self , other ): ...
57
- def __divmod__ (self , other ): ...
58
- def __rdivmod__ (self , other ): ...
59
- def __pow__ (self , other ): ...
60
- def __rpow__ (self , other ): ...
92
+ @overload
93
+ def __div__ (self , other : Union [int , Fraction ]) -> Fraction : ...
94
+ @overload
95
+ def __div__ (self , other : float ) -> float : ...
96
+ @overload
97
+ def __div__ (self , other : complex ) -> complex : ...
98
+ @overload
99
+ def __rdiv__ (self , other : Union [int , Fraction ]) -> Fraction : ...
100
+ @overload
101
+ def __rdiv__ (self , other : float ) -> float : ...
102
+ @overload
103
+ def __rdiv__ (self , other : complex ) -> complex : ...
104
+ @overload
105
+ def __floordiv__ (self , other : Union [int , Fraction ]) -> int : ...
106
+ @overload
107
+ def __floordiv__ (self , other : float ) -> float : ...
108
+ @overload
109
+ def __rfloordiv__ (self , other : Union [int , Fraction ]) -> int : ...
110
+ @overload
111
+ def __rfloordiv__ (self , other : float ) -> float : ...
112
+ @overload
113
+ def __mod__ (self , other : Union [int , Fraction ]) -> Fraction : ...
114
+ @overload
115
+ def __mod__ (self , other : float ) -> float : ...
116
+ @overload
117
+ def __rmod__ (self , other : Union [int , Fraction ]) -> Fraction : ...
118
+ @overload
119
+ def __rmod__ (self , other : float ) -> float : ...
120
+ @overload
121
+ def __divmod__ (self , other : Union [int , Fraction ]) -> Tuple [int , Fraction ]: ...
122
+ @overload
123
+ def __divmod__ (self , other : float ) -> Tuple [float , Fraction ]: ...
124
+ @overload
125
+ def __rdivmod__ (self , other : Union [int , Fraction ]) -> Tuple [int , Fraction ]: ...
126
+ @overload
127
+ def __rdivmod__ (self , other : float ) -> Tuple [float , Fraction ]: ...
128
+ @overload
129
+ def __pow__ (self , other : int ) -> Fraction : ...
130
+ @overload
131
+ def __pow__ (self , other : Union [float , Fraction ]) -> float : ...
132
+ @overload
133
+ def __pow__ (self , other : complex ) -> complex : ...
134
+ @overload
135
+ def __rpow__ (self , other : Union [int , float , Fraction ]) -> float : ...
136
+ @overload
137
+ def __rpow__ (self , other : complex ) -> complex : ...
61
138
def __pos__ (self ) -> Fraction : ...
62
139
def __neg__ (self ) -> Fraction : ...
63
140
def __abs__ (self ) -> Fraction : ...
64
141
def __trunc__ (self ) -> int : ...
65
142
if sys .version_info >= (3 , 0 ):
66
143
def __floor__ (self ) -> int : ...
67
144
def __ceil__ (self ) -> int : ...
68
- def __round__ (self , ndigits : Optional [Any ] = ...): ...
145
+ @overload
146
+ def __round__ (self , ndigits : int ) -> Fraction : ...
147
+ @overload
148
+ def __round__ (self , ndigits : None = ...) -> int : ...
69
149
def __hash__ (self ) -> int : ...
70
150
def __eq__ (self , other : object ) -> bool : ...
71
151
def __lt__ (self , other : _ComparableNum ) -> bool : ...
@@ -81,5 +161,5 @@ class Fraction(Rational):
81
161
@property
82
162
def real (self ) -> Fraction : ...
83
163
@property
84
- def imag (self ) -> Fraction : ...
164
+ def imag (self ) -> Literal [ 0 ] : ...
85
165
def conjugate (self ) -> Fraction : ...
0 commit comments