|
| 1 | +import sys |
1 | 2 | from builtins import bool as py_bool |
2 | | -from typing import Any, Final, Literal as L, TypedDict, type_check_only |
3 | | - |
4 | | -import numpy as np |
| 3 | +from typing import Any, Final, Literal as L, TypeAlias, TypedDict, type_check_only |
5 | 4 |
|
6 | 5 | # ruff: noqa: ICN003 |
7 | 6 | from numpy import ( |
@@ -154,41 +153,114 @@ class _TypeCodes(TypedDict): |
154 | 153 | ### |
155 | 154 |
|
156 | 155 | typecodes: Final[_TypeCodes] = ... |
157 | | -ScalarType: Final[ |
158 | | - tuple[ |
| 156 | + |
| 157 | +# 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[ |
159 | 196 | type[int], |
160 | 197 | type[float], |
161 | 198 | type[complex], |
162 | 199 | type[py_bool], |
163 | 200 | type[bytes], |
164 | 201 | type[str], |
165 | 202 | type[memoryview[Any]], |
166 | | - type[np.bool], |
167 | | - type[csingle], |
168 | | - type[cdouble], |
| 203 | + type[Any], # TODO: bool_? |
| 204 | + type[complex64], |
| 205 | + type[complex128], |
169 | 206 | type[clongdouble], |
170 | | - type[half], |
171 | | - type[single], |
172 | | - type[double], |
| 207 | + type[float16], |
| 208 | + type[float32], |
| 209 | + type[float64], |
173 | 210 | type[longdouble], |
174 | | - type[byte], |
175 | | - type[short], |
176 | | - type[intc], |
177 | | - type[long], |
| 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], |
178 | 249 | type[longlong], |
179 | | - type[timedelta64], |
180 | | - type[datetime64], |
| 250 | + type[timedelta64[Any]], |
| 251 | + type[datetime64[Any]], |
181 | 252 | type[object_], |
182 | 253 | type[bytes_], |
183 | 254 | type[str_], |
184 | | - type[ubyte], |
185 | | - type[ushort], |
186 | | - type[uintc], |
187 | | - type[ulong], |
| 255 | + type[uint8], |
| 256 | + type[uint16], |
| 257 | + type[uint32], |
| 258 | + type[uint64], |
188 | 259 | type[ulonglong], |
189 | 260 | type[void], |
190 | 261 | ] |
191 | | -] = ... |
| 262 | + |
| 263 | +ScalarType: Final[_ScalarTypeTuple] = ... |
192 | 264 | typeDict: Final = sctypeDict |
193 | 265 |
|
194 | 266 | def isdtype(dtype: dtype | type, kind: DTypeLike | tuple[DTypeLike, ...]) -> py_bool: ... |
|
0 commit comments