Skip to content

Commit 2ea5e3e

Browse files
committed
♻️ replace NDArray with _nt.Array in the stubs
1 parent 3424b7f commit 2ea5e3e

File tree

14 files changed

+787
-763
lines changed

14 files changed

+787
-763
lines changed

src/numpy-stubs/@test/static/accept/chararray.pyi

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
from typing import TypeAlias, assert_type
1+
from typing import Any, TypeAlias, assert_type
2+
from typing_extensions import TypeVar
23

34
import _numtype as _nt
45
import numpy as np
56

6-
_BytesArray: TypeAlias = np.char.chararray[_nt.Shape, np.dtype[np.bytes_]]
7-
_StrArray: TypeAlias = np.char.chararray[_nt.Shape, np.dtype[np.str_]]
7+
_ShapeT = TypeVar("_ShapeT", bound=_nt.Shape, default=_nt.Shape)
8+
9+
_BytesArray: TypeAlias = np.char.chararray[_ShapeT, np.dtype[np.bytes_]]
10+
_StrArray: TypeAlias = np.char.chararray[_ShapeT, np.dtype[np.str_]]
11+
12+
###
813

914
AR_U: _StrArray
1015
AR_S: _BytesArray
@@ -85,8 +90,8 @@ assert_type(AR_S.title(), _BytesArray)
8590
assert_type(AR_U.upper(), _StrArray)
8691
assert_type(AR_S.upper(), _BytesArray)
8792

88-
assert_type(AR_U.zfill(5), _StrArray)
89-
assert_type(AR_S.zfill([2, 3, 4]), _BytesArray)
93+
assert_type(AR_U.zfill(5), _StrArray[Any])
94+
assert_type(AR_S.zfill([2, 3, 4]), _BytesArray[Any])
9095

9196
assert_type(AR_U.count("a", start=[1, 2, 3]), _nt.Array[np.int_])
9297
assert_type(AR_S.count([b"a", b"b", b"c"], end=9), _nt.Array[np.int_])

src/numpy-stubs/__init__.pyi

Lines changed: 436 additions & 418 deletions
Large diffs are not rendered by default.

src/numpy-stubs/_core/arrayprint.pyi

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from collections.abc import Callable
22
from contextlib import _GeneratorContextManager
3-
from typing import Any, Final, Literal, SupportsIndex, TypeAlias, TypedDict, overload, type_check_only
3+
from typing import Final, Literal, SupportsIndex, TypeAlias, TypedDict, overload, type_check_only
44
from typing_extensions import deprecated
55

6+
import _numtype as _nt
67
import numpy as np
78
from numpy._globals import _NoValueType
8-
from numpy._typing import NDArray, _CharLike_co, _FloatLike_co
9+
from numpy._typing import _CharLike_co, _FloatLike_co
910

1011
__all__ = [
1112
"array2string",
@@ -25,7 +26,7 @@ _Sign: TypeAlias = Literal["-", "+", " "]
2526
_Trim: TypeAlias = Literal["k", ".", "0", "-"]
2627
_Legacy: TypeAlias = Literal["1.13", "1.21", "1.25", "2.1", False]
2728
_LegacyNoStyle: TypeAlias = Literal["1.21", "1.25", "2.1", False]
28-
_ReprFunc: TypeAlias = Callable[[NDArray[Any]], str]
29+
_ReprFunc: TypeAlias = Callable[[_nt.Array], str]
2930

3031
@type_check_only
3132
class _FormatDict(TypedDict, total=False):
@@ -104,7 +105,7 @@ def printoptions(
104105
# public numpy export
105106
@overload # no style
106107
def array2string(
107-
a: NDArray[Any],
108+
a: _nt.Array,
108109
max_line_width: int | None = None,
109110
precision: SupportsIndex | None = None,
110111
suppress_small: bool | None = None,
@@ -122,7 +123,7 @@ def array2string(
122123
) -> str: ...
123124
@overload # style=<given> (positional), legacy="1.13"
124125
def array2string(
125-
a: NDArray[Any],
126+
a: _nt.Array,
126127
max_line_width: int | None,
127128
precision: SupportsIndex | None,
128129
suppress_small: bool | None,
@@ -140,7 +141,7 @@ def array2string(
140141
) -> str: ...
141142
@overload # style=<given> (keyword), legacy="1.13"
142143
def array2string(
143-
a: NDArray[Any],
144+
a: _nt.Array,
144145
max_line_width: int | None = None,
145146
precision: SupportsIndex | None = None,
146147
suppress_small: bool | None = None,
@@ -159,7 +160,7 @@ def array2string(
159160
@overload # style=<given> (positional), legacy!="1.13"
160161
@deprecated("'style' argument is deprecated and no longer functional except in 1.13 'legacy' mode")
161162
def array2string(
162-
a: NDArray[Any],
163+
a: _nt.Array,
163164
max_line_width: int | None,
164165
precision: SupportsIndex | None,
165166
suppress_small: bool | None,
@@ -178,7 +179,7 @@ def array2string(
178179
@overload # style=<given> (keyword), legacy="1.13"
179180
@deprecated("'style' argument is deprecated and no longer functional except in 1.13 'legacy' mode")
180181
def array2string(
181-
a: NDArray[Any],
182+
a: _nt.Array,
182183
max_line_width: int | None = None,
183184
precision: SupportsIndex | None = None,
184185
suppress_small: bool | None = None,
@@ -222,15 +223,15 @@ def format_float_positional(
222223

223224
# public numpy export
224225
def array_repr(
225-
arr: NDArray[Any],
226+
arr: _nt.Array,
226227
max_line_width: int | None = None,
227228
precision: SupportsIndex | None = None,
228229
suppress_small: bool | None = None,
229230
) -> str: ...
230231

231232
# public numpy export
232233
def array_str(
233-
a: NDArray[Any],
234+
a: _nt.Array,
234235
max_line_width: int | None = None,
235236
precision: SupportsIndex | None = None,
236237
suppress_small: bool | None = None,

src/numpy-stubs/_core/function_base.pyi

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
from typing import Any, Literal as L, SupportsIndex, TypeAlias, overload
1+
from _typeshed import Incomplete
2+
from typing import Literal as L, SupportsIndex, TypeAlias, overload
23
from typing_extensions import TypeVar
34

5+
import _numtype as _nt
46
import numpy as np
5-
from numpy._typing import DTypeLike, NDArray, _ArrayLikeFloat_co, _ArrayLikeNumber_co, _DTypeLike
7+
from numpy._typing import DTypeLike, _ArrayLikeFloat_co, _ArrayLikeNumber_co, _DTypeLike
68

79
__all__ = ["geomspace", "linspace", "logspace"]
810

@@ -25,7 +27,7 @@ def linspace(
2527
axis: SupportsIndex = 0,
2628
*,
2729
device: _Device | None = None,
28-
) -> NDArray[np.floating]: ...
30+
) -> _nt.Array[np.floating]: ...
2931
@overload
3032
def linspace(
3133
start: _ArrayLikeNumber_co,
@@ -37,7 +39,7 @@ def linspace(
3739
axis: SupportsIndex = 0,
3840
*,
3941
device: _Device | None = None,
40-
) -> NDArray[np.inexact]: ...
42+
) -> _nt.Array[np.inexact]: ...
4143
@overload
4244
def linspace(
4345
start: _ArrayLikeNumber_co,
@@ -49,7 +51,7 @@ def linspace(
4951
axis: SupportsIndex = 0,
5052
*,
5153
device: _Device | None = None,
52-
) -> NDArray[_ScalarT]: ...
54+
) -> _nt.Array[_ScalarT]: ...
5355
@overload
5456
def linspace(
5557
start: _ArrayLikeNumber_co,
@@ -61,7 +63,7 @@ def linspace(
6163
dtype: _DTypeLike[_ScalarT],
6264
axis: SupportsIndex = 0,
6365
device: _Device | None = None,
64-
) -> NDArray[_ScalarT]: ...
66+
) -> _nt.Array[_ScalarT]: ...
6567
@overload
6668
def linspace(
6769
start: _ArrayLikeNumber_co,
@@ -73,7 +75,7 @@ def linspace(
7375
axis: SupportsIndex = 0,
7476
*,
7577
device: _Device | None = None,
76-
) -> NDArray[Any]: ...
78+
) -> _nt.Array[Incomplete]: ...
7779
@overload
7880
def linspace(
7981
start: _ArrayLikeFloat_co,
@@ -85,7 +87,7 @@ def linspace(
8587
dtype: None = None,
8688
axis: SupportsIndex = 0,
8789
device: _Device | None = None,
88-
) -> tuple[NDArray[np.floating], np.floating]: ...
90+
) -> tuple[_nt.Array[np.floating], np.floating]: ...
8991
@overload
9092
def linspace(
9193
start: _ArrayLikeNumber_co,
@@ -97,7 +99,7 @@ def linspace(
9799
dtype: None = None,
98100
axis: SupportsIndex = 0,
99101
device: _Device | None = None,
100-
) -> tuple[NDArray[np.inexact], np.inexact]: ...
102+
) -> tuple[_nt.Array[np.inexact], np.inexact]: ...
101103
@overload
102104
def linspace(
103105
start: _ArrayLikeNumber_co,
@@ -109,7 +111,7 @@ def linspace(
109111
dtype: _DTypeLike[_ScalarT],
110112
axis: SupportsIndex = 0,
111113
device: _Device | None = None,
112-
) -> tuple[NDArray[_ScalarT], _ScalarT]: ...
114+
) -> tuple[_nt.Array[_ScalarT], _ScalarT]: ...
113115
@overload
114116
def linspace(
115117
start: _ArrayLikeNumber_co,
@@ -121,7 +123,7 @@ def linspace(
121123
dtype: DTypeLike = ...,
122124
axis: SupportsIndex = 0,
123125
device: _Device | None = None,
124-
) -> tuple[NDArray[Any], Any]: ...
126+
) -> tuple[_nt.Array[Incomplete], Incomplete]: ...
125127

126128
#
127129
@overload
@@ -133,7 +135,7 @@ def logspace(
133135
base: _ArrayLikeFloat_co = 10.0,
134136
dtype: None = None,
135137
axis: SupportsIndex = 0,
136-
) -> NDArray[np.floating]: ...
138+
) -> _nt.Array[np.floating]: ...
137139
@overload
138140
def logspace(
139141
start: _ArrayLikeNumber_co,
@@ -143,7 +145,7 @@ def logspace(
143145
base: _ArrayLikeNumber_co = 10.0,
144146
dtype: None = None,
145147
axis: SupportsIndex = 0,
146-
) -> NDArray[np.inexact]: ...
148+
) -> _nt.Array[np.inexact]: ...
147149
@overload
148150
def logspace(
149151
start: _ArrayLikeNumber_co,
@@ -153,7 +155,7 @@ def logspace(
153155
base: _ArrayLikeNumber_co,
154156
dtype: _DTypeLike[_ScalarT],
155157
axis: SupportsIndex = 0,
156-
) -> NDArray[_ScalarT]: ...
158+
) -> _nt.Array[_ScalarT]: ...
157159
@overload
158160
def logspace(
159161
start: _ArrayLikeNumber_co,
@@ -164,7 +166,7 @@ def logspace(
164166
*,
165167
dtype: _DTypeLike[_ScalarT],
166168
axis: SupportsIndex = 0,
167-
) -> NDArray[_ScalarT]: ...
169+
) -> _nt.Array[_ScalarT]: ...
168170
@overload
169171
def logspace(
170172
start: _ArrayLikeNumber_co,
@@ -174,7 +176,7 @@ def logspace(
174176
base: _ArrayLikeNumber_co = 10.0,
175177
dtype: DTypeLike = ...,
176178
axis: SupportsIndex = 0,
177-
) -> NDArray[Any]: ...
179+
) -> _nt.Array[Incomplete]: ...
178180

179181
#
180182
@overload
@@ -185,7 +187,7 @@ def geomspace(
185187
endpoint: bool = True,
186188
dtype: None = None,
187189
axis: SupportsIndex = 0,
188-
) -> NDArray[np.floating]: ...
190+
) -> _nt.Array[np.floating]: ...
189191
@overload
190192
def geomspace(
191193
start: _ArrayLikeNumber_co,
@@ -194,7 +196,7 @@ def geomspace(
194196
endpoint: bool = True,
195197
dtype: None = None,
196198
axis: SupportsIndex = 0,
197-
) -> NDArray[np.inexact]: ...
199+
) -> _nt.Array[np.inexact]: ...
198200
@overload
199201
def geomspace(
200202
start: _ArrayLikeNumber_co,
@@ -203,7 +205,7 @@ def geomspace(
203205
endpoint: bool,
204206
dtype: _DTypeLike[_ScalarT],
205207
axis: SupportsIndex = 0,
206-
) -> NDArray[_ScalarT]: ...
208+
) -> _nt.Array[_ScalarT]: ...
207209
@overload
208210
def geomspace(
209211
start: _ArrayLikeNumber_co,
@@ -213,7 +215,7 @@ def geomspace(
213215
*,
214216
dtype: _DTypeLike[_ScalarT],
215217
axis: SupportsIndex = 0,
216-
) -> NDArray[_ScalarT]: ...
218+
) -> _nt.Array[_ScalarT]: ...
217219
@overload
218220
def geomspace(
219221
start: _ArrayLikeNumber_co,
@@ -222,7 +224,7 @@ def geomspace(
222224
endpoint: bool = True,
223225
dtype: DTypeLike | None = None,
224226
axis: SupportsIndex = 0,
225-
) -> NDArray[Any]: ...
227+
) -> _nt.Array[Incomplete]: ...
226228

227229
#
228230
def add_newdoc(

0 commit comments

Comments
 (0)