Skip to content

Commit 899756c

Browse files
committed
🎨 refactor from _numtype import in ctypeslib
1 parent 55aba94 commit 899756c

1 file changed

Lines changed: 20 additions & 20 deletions

File tree

‎src/numpy-stubs/ctypeslib.pyi‎

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ from collections.abc import Iterable, Sequence
55
from typing import Any, ClassVar, Generic, Literal as L, TypeAlias, overload
66
from typing_extensions import TypeVar
77

8+
import _numtype as _nt
89
import numpy as np
9-
from _numtype import JustInt
1010
from numpy._core._internal import _ctypes
1111
from numpy._core.multiarray import flagsobj
12-
from numpy._typing import NDArray, _ArrayLike, _BoolCodes, _DTypeLike, _Shape, _ShapeLike, _VoidDTypeLike
12+
from numpy._typing import _ArrayLike, _BoolCodes, _DTypeLike, _Shape, _ShapeLike, _VoidDTypeLike
1313
from numpy._typing._char_codes import (
1414
_Float32Codes,
1515
_Float64Codes,
@@ -66,7 +66,7 @@ class _ndptr(ct.c_void_p, Generic[_DTypeT0_co, _ShapeT0_co]):
6666
def from_param(cls: type[_ndptr[_DTypeT, _ShapeT]], obj: np.ndarray[_ShapeT, _DTypeT]) -> _ctypes[int]: ...
6767
@overload
6868
@classmethod
69-
def from_param(cls: type[_ndptr], obj: NDArray[Any]) -> _ctypes[int]: ... # pyright: ignore[reportIncompatibleMethodOverride]
69+
def from_param(cls: type[_ndptr], obj: _nt.Array[Any]) -> _ctypes[int]: ... # pyright: ignore[reportIncompatibleMethodOverride]
7070

7171
class _concrete_ndptr(_ndptr[_DTypeT_co, _ShapeT_co], Generic[_DTypeT_co, _ShapeT_co]):
7272
def _check_retval_(self) -> np.ndarray[_ShapeT_co, _DTypeT_co]: ...
@@ -116,65 +116,65 @@ def ndpointer(
116116

117117
#
118118
@overload
119-
def as_array(obj: ct._PointerLike, shape: Sequence[int]) -> NDArray[Any]: ...
119+
def as_array(obj: ct._PointerLike, shape: Sequence[int]) -> _nt.Array[Any]: ...
120120
@overload
121-
def as_array(obj: _ArrayLike[_ScalarT], shape: _ShapeLike | None = ...) -> NDArray[_ScalarT]: ...
121+
def as_array(obj: _ArrayLike[_ScalarT], shape: _ShapeLike | None = ...) -> _nt.Array[_ScalarT]: ...
122122
@overload
123-
def as_array(obj: object, shape: _ShapeLike | None = ...) -> NDArray[Any]: ...
123+
def as_array(obj: object, shape: _ShapeLike | None = ...) -> _nt.Array[Any]: ...
124124

125125
# NOTE: The overlapping overloads ignores are a temporary workaround for the non-unique
126126
# intp/long/longlong issues, and otherwise mypy false positives.
127127
# NOTE: `as_ctypes` doesn't support `void` values at the moment
128128
@overload # bool
129129
def as_ctypes(obj: np.bool) -> ct.c_bool: ...
130130
@overload
131-
def as_ctypes(obj: NDArray[np.bool]) -> ct.Array[ct.c_bool]: ...
131+
def as_ctypes(obj: _nt.Array[np.bool]) -> ct.Array[ct.c_bool]: ...
132132
@overload # int8 / byte
133133
def as_ctypes(obj: np.int8) -> ct.c_int8: ...
134134
@overload
135-
def as_ctypes(obj: NDArray[np.int8]) -> ct.Array[ct.c_int8]: ...
135+
def as_ctypes(obj: _nt.Array[np.int8]) -> ct.Array[ct.c_int8]: ...
136136
@overload # int16 / short
137137
def as_ctypes(obj: np.int16) -> ct.c_int16: ...
138138
@overload
139-
def as_ctypes(obj: NDArray[np.int16]) -> ct.Array[ct.c_int16]: ...
139+
def as_ctypes(obj: _nt.Array[np.int16]) -> ct.Array[ct.c_int16]: ...
140140
@overload # int32 / int[c]
141141
def as_ctypes(obj: np.int32) -> ct.c_int32: ...
142142
@overload
143-
def as_ctypes(obj: NDArray[np.int32]) -> ct.Array[ct.c_int32]: ...
143+
def as_ctypes(obj: _nt.Array[np.int32]) -> ct.Array[ct.c_int32]: ...
144144
@overload # int64 / longlong (which might be an alias for for `long`)
145145
def as_ctypes(obj: np.int64) -> ct.c_int64: ...
146146
@overload
147-
def as_ctypes(obj: NDArray[np.int64]) -> ct.Array[ct.c_int64]: ...
147+
def as_ctypes(obj: _nt.Array[np.int64]) -> ct.Array[ct.c_int64]: ...
148148
@overload # uint8 / ubyte
149149
def as_ctypes(obj: np.uint8) -> ct.c_uint8: ...
150150
@overload
151-
def as_ctypes(obj: NDArray[np.uint8]) -> ct.Array[ct.c_uint8]: ...
151+
def as_ctypes(obj: _nt.Array[np.uint8]) -> ct.Array[ct.c_uint8]: ...
152152
@overload # uint16 / ushort
153153
def as_ctypes(obj: np.uint16) -> ct.c_uint16: ...
154154
@overload
155-
def as_ctypes(obj: NDArray[np.uint16]) -> ct.Array[ct.c_uint16]: ...
155+
def as_ctypes(obj: _nt.Array[np.uint16]) -> ct.Array[ct.c_uint16]: ...
156156
@overload # uint32 / uint
157157
def as_ctypes(obj: np.uint32) -> ct.c_uint32: ...
158158
@overload
159-
def as_ctypes(obj: NDArray[np.uint32]) -> ct.Array[ct.c_uint32]: ...
159+
def as_ctypes(obj: _nt.Array[np.uint32]) -> ct.Array[ct.c_uint32]: ...
160160
@overload # uint64 / ulonglong
161161
def as_ctypes(obj: np.uint64) -> ct.c_uint64: ...
162162
@overload
163-
def as_ctypes(obj: NDArray[np.uint64]) -> ct.Array[ct.c_uint64]: ...
163+
def as_ctypes(obj: _nt.Array[np.uint64]) -> ct.Array[ct.c_uint64]: ...
164164
@overload # float32 / single / float
165165
def as_ctypes(obj: np.float32) -> ct.c_float: ...
166166
@overload
167-
def as_ctypes(obj: NDArray[np.float32]) -> ct.Array[ct.c_float]: ...
167+
def as_ctypes(obj: _nt.Array[np.float32]) -> ct.Array[ct.c_float]: ...
168168
@overload # float64 / double
169169
def as_ctypes(obj: np.float64) -> ct.c_double: ...
170170
@overload
171-
def as_ctypes(obj: NDArray[np.float64]) -> ct.Array[ct.c_double]: ...
171+
def as_ctypes(obj: _nt.Array[np.float64]) -> ct.Array[ct.c_double]: ...
172172
@overload # float96 / float128 / longdouble
173173
def as_ctypes(obj: np.longdouble) -> ct.c_longdouble: ...
174174
@overload
175-
def as_ctypes(obj: NDArray[np.longdouble]) -> ct.Array[ct.c_longdouble]: ...
175+
def as_ctypes(obj: _nt.Array[np.longdouble]) -> ct.Array[ct.c_longdouble]: ...
176176

177-
#
177+
# TODO(jorenham): https://github.com/numpy/numtype/issues/522
178178
@overload
179179
def as_ctypes_type(dtype: _DTypeLike[np.bool] | type[bool | ct.c_bool] | _BoolCodes) -> type[ct.c_bool]: ...
180180
@overload
@@ -186,7 +186,7 @@ def as_ctypes_type(dtype: _DTypeLike[np.int32] | type[ct.c_int32 | ct.c_int] | _
186186
@overload
187187
def as_ctypes_type(dtype: type[ct.c_long] | _LongCodes) -> type[ct.c_long]: ...
188188
@overload
189-
def as_ctypes_type(dtype: type[JustInt | ct.c_ssize_t] | _IntPCodes) -> type[ct.c_ssize_t]: ...
189+
def as_ctypes_type(dtype: type[_nt.JustInt | ct.c_ssize_t] | _IntPCodes) -> type[ct.c_ssize_t]: ...
190190
@overload
191191
def as_ctypes_type(dtype: _DTypeLike[np.int64] | type[ct.c_int64] | _Int64Codes) -> type[ct.c_int64]: ...
192192
@overload

0 commit comments

Comments
 (0)