Skip to content

Commit f1e7334

Browse files
authored
💥 change [u]long into a platform-dependent type alias (#478)
1 parent 171aa3f commit f1e7334

File tree

4 files changed

+14
-43
lines changed

4 files changed

+14
-43
lines changed

‎src/numpy-stubs/@test/static/accept/ctypeslib.pyi

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ AR_i1: npt.NDArray[np.int8]
1313
AR_i2: npt.NDArray[np.int16]
1414
AR_i4: npt.NDArray[np.int32]
1515
AR_i8: npt.NDArray[np.int64]
16-
AR_l: npt.NDArray[np.long]
16+
AR_q: npt.NDArray[np.longlong]
1717
AR_u1: npt.NDArray[np.uint8]
1818
AR_u2: npt.NDArray[np.uint16]
1919
AR_u4: npt.NDArray[np.uint32]
@@ -81,7 +81,3 @@ assert_type(np.ctypeslib.as_array(pointer), npt.NDArray[Any])
8181

8282
assert_type(np.ctypeslib.as_ctypes_type(int), type[ct.c_ssize_t])
8383
assert_type(np.ctypeslib.as_ctypes_type("N"), type[ct.c_size_t])
84-
assert_type(np.ctypeslib.as_ctypes(AR_l), ct.Array[ct.c_long])
85-
assert_type(np.ctypeslib.as_ctypes(AR_l.take(0)), ct.c_long)
86-
assert_type(np.ctypeslib.as_ctypes(AR_L), ct.Array[ct.c_ulong])
87-
assert_type(np.ctypeslib.as_ctypes(AR_L.take(0)), ct.c_ulong)

‎src/numpy-stubs/@test/static/accept/dtype.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ assert_type(np.dtype(Fraction), np.dtype[np.object_])
6767

6868
# char-codes
6969
assert_type(np.dtype("u1"), np.dtype[np.uint8])
70-
assert_type(np.dtype("l"), np.dtype[np.long])
70+
assert_type(np.dtype("int_"), np.dtype[np.intp])
7171
assert_type(np.dtype("longlong"), np.dtype[np.longlong])
7272
assert_type(np.dtype(">g"), np.dtype[np.longdouble])
7373
assert_type(np.dtype(cs_integer), np.dtype[np.integer])

‎src/numpy-stubs/__init__.pyi

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7902,29 +7902,12 @@ ushort = uint16
79027902
intc = int32
79037903
uintc = uint32
79047904

7905-
class long(signedinteger[_n._32_64]):
7906-
@property
7907-
@override
7908-
def itemsize(self) -> L[4, 8]: ...
7909-
@property
7910-
@override
7911-
def nbytes(self) -> L[4, 8]: ...
7912-
@override
7913-
def __hash__(self, /) -> int: ...
7914-
def __index__(self, /) -> int: ...
7915-
def bit_count(self, /) -> int: ...
7916-
7917-
class ulong(unsignedinteger[_n._32_64]):
7918-
@property
7919-
@override
7920-
def itemsize(self) -> L[4, 8]: ...
7921-
@property
7922-
@override
7923-
def nbytes(self) -> L[4, 8]: ...
7924-
@override
7925-
def __hash__(self, /) -> int: ...
7926-
def __index__(self, /) -> int: ...
7927-
def bit_count(self, /) -> int: ...
7905+
if sys.platform == "win32":
7906+
long: TypeAlias = int32 # pyright: ignore[reportRedeclaration]
7907+
ulong: TypeAlias = uint32 # pyright: ignore[reportRedeclaration]
7908+
else:
7909+
long: TypeAlias = intp # pyright: ignore[reportRedeclaration]
7910+
ulong: TypeAlias = uintp # pyright: ignore[reportRedeclaration]
79287911

79297912
longlong = int64
79307913
ulonglong = uint64

‎src/numpy-stubs/ctypeslib.pyi

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,6 @@ def as_ctypes(obj: NDArray[np.int16]) -> ct.Array[ct.c_int16]: ...
141141
def as_ctypes(obj: np.int32) -> ct.c_int32: ...
142142
@overload
143143
def as_ctypes(obj: NDArray[np.int32]) -> ct.Array[ct.c_int32]: ...
144-
@overload # long
145-
def as_ctypes(obj: np.long) -> ct.c_long: ...
146-
@overload
147-
def as_ctypes(obj: NDArray[np.long]) -> ct.Array[ct.c_long]: ...
148144
@overload # int64 / longlong (which might be an alias for for `long`)
149145
def as_ctypes(obj: np.int64) -> ct.c_int64: ...
150146
@overload
@@ -161,10 +157,6 @@ def as_ctypes(obj: NDArray[np.uint16]) -> ct.Array[ct.c_uint16]: ...
161157
def as_ctypes(obj: np.uint32) -> ct.c_uint32: ...
162158
@overload
163159
def as_ctypes(obj: NDArray[np.uint32]) -> ct.Array[ct.c_uint32]: ...
164-
@overload # ulong
165-
def as_ctypes(obj: np.ulong) -> ct.c_ulong: ...
166-
@overload
167-
def as_ctypes(obj: NDArray[np.ulong]) -> ct.Array[ct.c_ulong]: ...
168160
@overload # uint64 / ulonglong
169161
def as_ctypes(obj: np.uint64) -> ct.c_uint64: ...
170162
@overload
@@ -192,23 +184,23 @@ def as_ctypes_type(dtype: _DTypeLike[np.int16] | type[ct.c_int16 | ct.c_short] |
192184
@overload
193185
def as_ctypes_type(dtype: _DTypeLike[np.int32] | type[ct.c_int32 | ct.c_int] | _Int32Codes) -> type[ct.c_int32]: ...
194186
@overload
195-
def as_ctypes_type(dtype: _DTypeLike[np.long] | type[ct.c_long] | _LongCodes) -> type[ct.c_long]: ...
196-
@overload
197-
def as_ctypes_type(dtype: _DTypeLike[np.int64] | type[ct.c_int64] | _Int64Codes) -> type[ct.c_int64]: ...
187+
def as_ctypes_type(dtype: type[ct.c_long] | _LongCodes) -> type[ct.c_long]: ...
198188
@overload
199189
def as_ctypes_type(dtype: type[JustInt | ct.c_ssize_t] | _IntPCodes) -> type[ct.c_ssize_t]: ...
200190
@overload
191+
def as_ctypes_type(dtype: _DTypeLike[np.int64] | type[ct.c_int64] | _Int64Codes) -> type[ct.c_int64]: ...
192+
@overload
201193
def as_ctypes_type(dtype: _DTypeLike[np.uint8] | type[ct.c_uint8 | ct.c_ubyte] | _UInt8Codes) -> type[ct.c_uint8]: ...
202194
@overload
203195
def as_ctypes_type(dtype: _DTypeLike[np.uint16] | type[ct.c_uint16 | ct.c_ushort] | _UInt16Codes) -> type[ct.c_uint16]: ...
204196
@overload
205197
def as_ctypes_type(dtype: _DTypeLike[np.uint32] | type[ct.c_uint32 | ct.c_uint] | _UInt32Codes) -> type[ct.c_uint32]: ...
206198
@overload
207-
def as_ctypes_type(dtype: _DTypeLike[np.ulong] | type[ct.c_ulong] | _ULongCodes) -> type[ct.c_ulong]: ...
199+
def as_ctypes_type(dtype: type[ct.c_ulong] | _ULongCodes) -> type[ct.c_ulong]: ...
208200
@overload
209-
def as_ctypes_type(dtype: _DTypeLike[np.uint64] | type[ct.c_uint64] | _UInt64Codes) -> type[ct.c_uint64]: ...
201+
def as_ctypes_type(dtype: type[ct.c_void_p | ct.c_size_t] | _UIntPCodes) -> type[ct.c_size_t]: ...
210202
@overload
211-
def as_ctypes_type(dtype: type[ct.c_size_t] | _UIntPCodes) -> type[ct.c_size_t]: ...
203+
def as_ctypes_type(dtype: _DTypeLike[np.uint64] | type[ct.c_uint64] | _UInt64Codes) -> type[ct.c_uint64]: ...
212204
@overload
213205
def as_ctypes_type(dtype: _DTypeLike[np.float32] | type[ct.c_float] | _Float32Codes) -> type[ct.c_float]: ...
214206
@overload

0 commit comments

Comments
 (0)