Skip to content

Commit f8dae9b

Browse files
committed
🐴 work around new platform-dependent ScalarTypes stubtest errors
1 parent f91936c commit f8dae9b

1 file changed

Lines changed: 94 additions & 22 deletions

File tree

src/numpy-stubs/_core/numerictypes.pyi

Lines changed: 94 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
import sys
12
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
54

65
# ruff: noqa: ICN003
76
from numpy import (
@@ -154,41 +153,114 @@ class _TypeCodes(TypedDict):
154153
###
155154

156155
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[
159196
type[int],
160197
type[float],
161198
type[complex],
162199
type[py_bool],
163200
type[bytes],
164201
type[str],
165202
type[memoryview[Any]],
166-
type[np.bool],
167-
type[csingle],
168-
type[cdouble],
203+
type[Any], # TODO: bool_?
204+
type[complex64],
205+
type[complex128],
169206
type[clongdouble],
170-
type[half],
171-
type[single],
172-
type[double],
207+
type[float16],
208+
type[float32],
209+
type[float64],
173210
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],
178249
type[longlong],
179-
type[timedelta64],
180-
type[datetime64],
250+
type[timedelta64[Any]],
251+
type[datetime64[Any]],
181252
type[object_],
182253
type[bytes_],
183254
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],
188259
type[ulonglong],
189260
type[void],
190261
]
191-
] = ...
262+
263+
ScalarType: Final[_ScalarTypeTuple] = ...
192264
typeDict: Final = sctypeDict
193265

194266
def isdtype(dtype: dtype | type, kind: DTypeLike | tuple[DTypeLike, ...]) -> py_bool: ...

0 commit comments

Comments
 (0)