|
1 | | -import sys |
2 | 1 | from builtins import bool as py_bool |
3 | 2 | from typing import Any, Final, Literal as L, TypeAlias, TypedDict, type_check_only |
4 | 3 |
|
@@ -155,110 +154,41 @@ class _TypeCodes(TypedDict): |
155 | 154 | typecodes: Final[_TypeCodes] = ... |
156 | 155 |
|
157 | 156 | # pyright: reportRedeclaration=false |
158 | | -# NOTE: The orders of float64/longdouble, int32/int64, and timedelta64/datetime64 are platform dependent. |
159 | | -# NOTE: We assume 64-bit platforms here. |
160 | | -if sys.platform == "darwin": |
161 | | - _ScalarTypeTuple: TypeAlias = tuple[ |
162 | | - type[int], |
163 | | - type[float], |
164 | | - type[complex], |
165 | | - type[py_bool], |
166 | | - type[bytes], |
167 | | - type[str], |
168 | | - type[memoryview[Any]], |
169 | | - type[Any], # TODO: bool_? |
170 | | - type[complex64], |
171 | | - type[complex128], |
172 | | - type[clongdouble], |
173 | | - type[float16], |
174 | | - type[float32], |
175 | | - type[longdouble], |
176 | | - type[float64], |
177 | | - type[int8], |
178 | | - type[int16], |
179 | | - type[int32], |
180 | | - type[int64], |
181 | | - type[Any], # TODO: longlong? |
182 | | - type[datetime64[Any]], |
183 | | - type[timedelta64[Any]], |
184 | | - type[object_], |
185 | | - type[bytes_], |
186 | | - type[str_], |
187 | | - type[uint8], |
188 | | - type[uint16], |
189 | | - type[uint32], |
190 | | - type[uint64], |
191 | | - type[Any], # TODO: ulonglong? |
192 | | - type[void], |
193 | | - ] |
194 | | -elif sys.platform == "win32": |
195 | | - _ScalarTypeTuple: TypeAlias = tuple[ |
196 | | - type[int], |
197 | | - type[float], |
198 | | - type[complex], |
199 | | - type[py_bool], |
200 | | - type[bytes], |
201 | | - type[str], |
202 | | - type[memoryview[Any]], |
203 | | - type[Any], # TODO: bool_? |
204 | | - type[complex64], |
205 | | - type[complex128], |
206 | | - type[clongdouble], |
207 | | - type[float16], |
208 | | - type[float32], |
209 | | - type[float64], |
210 | | - type[longdouble], |
211 | | - type[int8], |
212 | | - type[int16], |
213 | | - type[int32], |
214 | | - type[Any], # TODO: intc? |
215 | | - type[int64], |
216 | | - type[datetime64[Any]], |
217 | | - type[timedelta64[Any]], |
218 | | - type[object_], |
219 | | - type[bytes_], |
220 | | - type[str_], |
221 | | - type[uint8], |
222 | | - type[uint16], |
223 | | - type[Any], # TODO: uintc? |
224 | | - type[uint32], |
225 | | - type[uint64], |
226 | | - type[void], |
227 | | - ] |
228 | | -else: # linux (presumed) |
229 | | - _ScalarTypeTuple: TypeAlias = tuple[ |
230 | | - type[int], |
231 | | - type[float], |
232 | | - type[complex], |
233 | | - type[py_bool], |
234 | | - type[bytes], |
235 | | - type[str], |
236 | | - type[memoryview[Any]], |
237 | | - type[bool_[Any]], |
238 | | - type[complex64], |
239 | | - type[complex128], |
240 | | - type[clongdouble], |
241 | | - type[float16], |
242 | | - type[float32], |
243 | | - type[float64], |
244 | | - type[longdouble], |
245 | | - type[int8], |
246 | | - type[int16], |
247 | | - type[int32], |
248 | | - type[int64], |
249 | | - type[longlong], |
250 | | - type[timedelta64[Any]], |
251 | | - type[datetime64[Any]], |
252 | | - type[object_], |
253 | | - type[bytes_], |
254 | | - type[str_], |
255 | | - type[uint8], |
256 | | - type[uint16], |
257 | | - type[uint32], |
258 | | - type[uint64], |
259 | | - type[ulonglong], |
260 | | - type[void], |
261 | | - ] |
| 157 | +# NOTE: The order of same-kind same-itemsize types are unstable, hence the `| Any` in some places. |
| 158 | +# See https://github.com/numpy/numpy/pull/29761 for details |
| 159 | +_ScalarTypeTuple: TypeAlias = tuple[ |
| 160 | + type[int], |
| 161 | + type[float], |
| 162 | + type[complex], |
| 163 | + type[py_bool], |
| 164 | + type[bytes], |
| 165 | + type[str], |
| 166 | + type[memoryview[Any]], |
| 167 | + type[bool_[Any]], |
| 168 | + type[complex64], |
| 169 | + type[complex128 | Any], |
| 170 | + type[clongdouble | Any], |
| 171 | + type[float16], |
| 172 | + type[float32], |
| 173 | + type[float64 | Any], |
| 174 | + type[longdouble | Any], |
| 175 | + type[int8], |
| 176 | + type[int16], |
| 177 | + type[int32 | Any], |
| 178 | + type[long | Any], |
| 179 | + type[int64], |
| 180 | + type[datetime64[Any] | Any], |
| 181 | + type[timedelta64[Any] | Any], |
| 182 | + type[object_], |
| 183 | + type[bytes_], |
| 184 | + type[str_], |
| 185 | + type[uint8], |
| 186 | + type[uint16], |
| 187 | + type[uint32 | Any], |
| 188 | + type[ulong | Any], |
| 189 | + type[uint64], |
| 190 | + type[void], |
| 191 | +] |
262 | 192 |
|
263 | 193 | ScalarType: Final[_ScalarTypeTuple] = ... |
264 | 194 | typeDict: Final = sctypeDict |
|
0 commit comments