Debian Codegraph @

jedi/third_party/typeshed/stdlib/numbers.pyi

raw symbols SCIP
1 # Note: these stubs are incomplete. The more complex type
2 # signatures are currently omitted.
3 #
4 # Use _ComplexLike, _RealLike and _IntegralLike for return types in this module
5 # rather than `numbers.Complex`, `numbers.Real` and `numbers.Integral`,
6 # to avoid an excessive number of `type: ignore`s in subclasses of these ABCs
7 # (since type checkers don't see `complex` as a subtype of `numbers.Complex`,
8 # nor `float` as a subtype of `numbers.Real`, etc.)
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 # Protocols for return types
17 ############################
18
19 # `_ComplexLike` is a structural-typing approximation
20 # of the `Complex` ABC, which is not (and cannot be) a protocol
21 #
22 # NOTE: We can't include `__complex__` here,
23 # as we want `int` to be seen as a subtype of `_ComplexLike`,
24 # and `int.__complex__` does not exist :(
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 # _RealLike is a structural-typing approximation
32 # of the `Real` ABC, which is not (and cannot be) a protocol
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 # Overridden from `_ComplexLike`
40 # for a more precise return type:
41 def __neg__(self) -> _RealLike: ...
42 def __pos__(self) -> _RealLike: ...
43
44 # _IntegralLike is a structural-typing approximation
45 # of the `Integral` ABC, which is not (and cannot be) a protocol
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 # Overridden from `_ComplexLike`
52 # for a more precise return type:
53 def __abs__(self) -> _IntegralLike: ...
54 # Overridden from `RealLike`
55 # for a more precise return type:
56 def __neg__(self) -> _IntegralLike: ...
57 def __pos__(self) -> _IntegralLike: ...
58
59 #################
60 # Module "proper"
61 #################
62
63 class Number(metaclass=ABCMeta):
64 __slots__ = ()
65 @abstractmethod
66 def __hash__(self) -> int: ...
67
68 # See comment at the top of the file
69 # for why some of these return types are purposefully vague
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] # type: ignore[assignment]
110
111 # See comment at the top of the file
112 # for why some of these return types are purposefully vague
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 # Not actually overridden at runtime,
150 # but we override these in the stub to give them more precise return types:
151 @abstractmethod
152 def __pos__(self) -> _RealLike: ...
153 @abstractmethod
154 def __neg__(self) -> _RealLike: ...
155
156 # See comment at the top of the file
157 # for why some of these return types are purposefully vague
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 # See comment at the top of the file
169 # for why some of these return types are purposefully vague
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 # Not actually overridden at runtime,
205 # but we override these in the stub to give them more precise return types:
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: ...