| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
from abc import ABCMeta, abstractmethod |
| 11 |
from typing import ClassVar, Literal, Protocol, overload, type_check_only |
| 12 |
|
| 13 |
__all__ = ["Number", "Complex", "Real", "Rational", "Integral"] |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
@type_check_only |
| 26 |
class _ComplexLike(Protocol): |
| 27 |
def __neg__(self) -> _ComplexLike: ... |
| 28 |
def __pos__(self) -> _ComplexLike: ... |
| 29 |
def __abs__(self) -> _RealLike: ... |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
@type_check_only |
| 34 |
class _RealLike(_ComplexLike, Protocol): |
| 35 |
def __trunc__(self) -> _IntegralLike: ... |
| 36 |
def __floor__(self) -> _IntegralLike: ... |
| 37 |
def __ceil__(self) -> _IntegralLike: ... |
| 38 |
def __float__(self) -> float: ... |
| 39 |
|
| 40 |
|
| 41 |
def __neg__(self) -> _RealLike: ... |
| 42 |
def __pos__(self) -> _RealLike: ... |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
@type_check_only |
| 47 |
class _IntegralLike(_RealLike, Protocol): |
| 48 |
def __invert__(self) -> _IntegralLike: ... |
| 49 |
def __int__(self) -> int: ... |
| 50 |
def __index__(self) -> int: ... |
| 51 |
|
| 52 |
|
| 53 |
def __abs__(self) -> _IntegralLike: ... |
| 54 |
|
| 55 |
|
| 56 |
def __neg__(self) -> _IntegralLike: ... |
| 57 |
def __pos__(self) -> _IntegralLike: ... |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
class Number(metaclass=ABCMeta): |
| 64 |
__slots__ = () |
| 65 |
@abstractmethod |
| 66 |
def __hash__(self) -> int: ... |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
class Complex(Number, _ComplexLike): |
| 71 |
__slots__ = () |
| 72 |
@abstractmethod |
| 73 |
def __complex__(self) -> complex: ... |
| 74 |
def __bool__(self) -> bool: ... |
| 75 |
@property |
| 76 |
@abstractmethod |
| 77 |
def real(self) -> _RealLike: ... |
| 78 |
@property |
| 79 |
@abstractmethod |
| 80 |
def imag(self) -> _RealLike: ... |
| 81 |
@abstractmethod |
| 82 |
def __add__(self, other) -> _ComplexLike: ... |
| 83 |
@abstractmethod |
| 84 |
def __radd__(self, other) -> _ComplexLike: ... |
| 85 |
@abstractmethod |
| 86 |
def __neg__(self) -> _ComplexLike: ... |
| 87 |
@abstractmethod |
| 88 |
def __pos__(self) -> _ComplexLike: ... |
| 89 |
def __sub__(self, other) -> _ComplexLike: ... |
| 90 |
def __rsub__(self, other) -> _ComplexLike: ... |
| 91 |
@abstractmethod |
| 92 |
def __mul__(self, other) -> _ComplexLike: ... |
| 93 |
@abstractmethod |
| 94 |
def __rmul__(self, other) -> _ComplexLike: ... |
| 95 |
@abstractmethod |
| 96 |
def __truediv__(self, other) -> _ComplexLike: ... |
| 97 |
@abstractmethod |
| 98 |
def __rtruediv__(self, other) -> _ComplexLike: ... |
| 99 |
@abstractmethod |
| 100 |
def __pow__(self, exponent) -> _ComplexLike: ... |
| 101 |
@abstractmethod |
| 102 |
def __rpow__(self, base) -> _ComplexLike: ... |
| 103 |
@abstractmethod |
| 104 |
def __abs__(self) -> _RealLike: ... |
| 105 |
@abstractmethod |
| 106 |
def conjugate(self) -> _ComplexLike: ... |
| 107 |
@abstractmethod |
| 108 |
def __eq__(self, other: object) -> bool: ... |
| 109 |
__hash__: ClassVar[None] |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
class Real(Complex, _RealLike): |
| 114 |
__slots__ = () |
| 115 |
@abstractmethod |
| 116 |
def __float__(self) -> float: ... |
| 117 |
@abstractmethod |
| 118 |
def __trunc__(self) -> _IntegralLike: ... |
| 119 |
@abstractmethod |
| 120 |
def __floor__(self) -> _IntegralLike: ... |
| 121 |
@abstractmethod |
| 122 |
def __ceil__(self) -> _IntegralLike: ... |
| 123 |
@abstractmethod |
| 124 |
@overload |
| 125 |
def __round__(self, ndigits: None = None) -> _IntegralLike: ... |
| 126 |
@abstractmethod |
| 127 |
@overload |
| 128 |
def __round__(self, ndigits: int) -> _RealLike: ... |
| 129 |
def __divmod__(self, other) -> tuple[_RealLike, _RealLike]: ... |
| 130 |
def __rdivmod__(self, other) -> tuple[_RealLike, _RealLike]: ... |
| 131 |
@abstractmethod |
| 132 |
def __floordiv__(self, other) -> _RealLike: ... |
| 133 |
@abstractmethod |
| 134 |
def __rfloordiv__(self, other) -> _RealLike: ... |
| 135 |
@abstractmethod |
| 136 |
def __mod__(self, other) -> _RealLike: ... |
| 137 |
@abstractmethod |
| 138 |
def __rmod__(self, other) -> _RealLike: ... |
| 139 |
@abstractmethod |
| 140 |
def __lt__(self, other) -> bool: ... |
| 141 |
@abstractmethod |
| 142 |
def __le__(self, other) -> bool: ... |
| 143 |
def __complex__(self) -> complex: ... |
| 144 |
@property |
| 145 |
def real(self) -> _RealLike: ... |
| 146 |
@property |
| 147 |
def imag(self) -> Literal[0]: ... |
| 148 |
def conjugate(self) -> _RealLike: ... |
| 149 |
|
| 150 |
|
| 151 |
@abstractmethod |
| 152 |
def __pos__(self) -> _RealLike: ... |
| 153 |
@abstractmethod |
| 154 |
def __neg__(self) -> _RealLike: ... |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
class Rational(Real): |
| 159 |
__slots__ = () |
| 160 |
@property |
| 161 |
@abstractmethod |
| 162 |
def numerator(self) -> _IntegralLike: ... |
| 163 |
@property |
| 164 |
@abstractmethod |
| 165 |
def denominator(self) -> _IntegralLike: ... |
| 166 |
def __float__(self) -> float: ... |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
class Integral(Rational, _IntegralLike): |
| 171 |
__slots__ = () |
| 172 |
@abstractmethod |
| 173 |
def __int__(self) -> int: ... |
| 174 |
def __index__(self) -> int: ... |
| 175 |
@abstractmethod |
| 176 |
def __pow__(self, exponent, modulus=None) -> _IntegralLike: ... |
| 177 |
@abstractmethod |
| 178 |
def __lshift__(self, other) -> _IntegralLike: ... |
| 179 |
@abstractmethod |
| 180 |
def __rlshift__(self, other) -> _IntegralLike: ... |
| 181 |
@abstractmethod |
| 182 |
def __rshift__(self, other) -> _IntegralLike: ... |
| 183 |
@abstractmethod |
| 184 |
def __rrshift__(self, other) -> _IntegralLike: ... |
| 185 |
@abstractmethod |
| 186 |
def __and__(self, other) -> _IntegralLike: ... |
| 187 |
@abstractmethod |
| 188 |
def __rand__(self, other) -> _IntegralLike: ... |
| 189 |
@abstractmethod |
| 190 |
def __xor__(self, other) -> _IntegralLike: ... |
| 191 |
@abstractmethod |
| 192 |
def __rxor__(self, other) -> _IntegralLike: ... |
| 193 |
@abstractmethod |
| 194 |
def __or__(self, other) -> _IntegralLike: ... |
| 195 |
@abstractmethod |
| 196 |
def __ror__(self, other) -> _IntegralLike: ... |
| 197 |
@abstractmethod |
| 198 |
def __invert__(self) -> _IntegralLike: ... |
| 199 |
def __float__(self) -> float: ... |
| 200 |
@property |
| 201 |
def numerator(self) -> _IntegralLike: ... |
| 202 |
@property |
| 203 |
def denominator(self) -> Literal[1]: ... |
| 204 |
|
| 205 |
|
| 206 |
@abstractmethod |
| 207 |
def __pos__(self) -> _IntegralLike: ... |
| 208 |
@abstractmethod |
| 209 |
def __neg__(self) -> _IntegralLike: ... |
| 210 |
@abstractmethod |
| 211 |
def __abs__(self) -> _IntegralLike: ... |
| 212 |
@abstractmethod |
| 213 |
@overload |
| 214 |
def __round__(self, ndigits: None = None) -> _IntegralLike: ... |
| 215 |
@abstractmethod |
| 216 |
@overload |
| 217 |
def __round__(self, ndigits: int) -> _IntegralLike: ... |