Skip to content

Commit aeb23f6

Browse files
authored
Merge pull request #246 from numpy/fix-remaining-_core-stubtest-errors
🏷️ fix remaining stubtest errors in `numpy._core`
2 parents 4a89cbe + e639f53 commit aeb23f6

File tree

4 files changed

+41
-34
lines changed

4 files changed

+41
-34
lines changed

.mypyignore-todo

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,9 @@ numpy(\..+)?\.floating.as_integer_ratio
88
numpy(\..+)?\.complexfloating.__hash__
99
numpy(\..+)?\.complexfloating.__complex__
1010

11-
numpy\._?core(\._multiarray_umath|\.multiarray)\.error
12-
numpy(\._core(\.memmap)?|\.matlib)?\.memmap\.__new__
1311
numpy(\.matrixlib(\.defmatrix)?|\.matlib)?\.matrix\.__new__
1412
numpy(\.lib\._polynomial_impl|\.matlib)?\.poly1d\.integ
1513

16-
numpy(\._?core(\.records)?|\.matlib|\.rec)?\.recarray\.__getattr__
17-
numpy(\._?core(\.records)?|\.matlib|\.rec)?\.recarray\.__new__
18-
numpy(\._?core(\.records)?|\.matlib|\.rec)?\.record\.__name__
19-
numpy(\._?core\.records|\.rec)\.array
20-
2114
numpy._globals._CopyMode.IF_NEEDED
2215
numpy._globals._CopyMode.__bool__
2316

src/numpy-stubs/_core/_multiarray_umath.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,8 @@ NAN: Final[float] = ...
385385

386386
###
387387

388-
error: Final = Exception
388+
# using `Final` or `TypeAlias` will break stubtest
389+
error = Exception
389390

390391
tracemalloc_domain: Final[int] = ...
391392
_extobj_contextvar: _contextvars.ContextVar[CapsuleType]

src/numpy-stubs/_core/memmap.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class memmap(np.ndarray[_ShapeT_co, _DType_co], Generic[_ShapeT_co, _DType_co]):
3636

3737
@overload
3838
def __new__(
39-
cls,
39+
subtype,
4040
filename: _ToFileName,
4141
dtype: type[np.uint8] = ...,
4242
mode: _ToMode = "r+",
@@ -46,7 +46,7 @@ class memmap(np.ndarray[_ShapeT_co, _DType_co], Generic[_ShapeT_co, _DType_co]):
4646
) -> memmap[Incomplete, np.dtype[np.uint8]]: ...
4747
@overload
4848
def __new__(
49-
cls,
49+
subtype,
5050
filename: _ToFileName,
5151
dtype: _DType_co,
5252
mode: _ToMode = "r+",
@@ -56,7 +56,7 @@ class memmap(np.ndarray[_ShapeT_co, _DType_co], Generic[_ShapeT_co, _DType_co]):
5656
) -> memmap[Incomplete, _DType_co]: ...
5757
@overload
5858
def __new__(
59-
cls,
59+
subtype,
6060
filename: _ToFileName,
6161
dtype: _DTypeLike[_ScalarT],
6262
mode: _ToMode = "r+",
@@ -66,7 +66,7 @@ class memmap(np.ndarray[_ShapeT_co, _DType_co], Generic[_ShapeT_co, _DType_co]):
6666
) -> memmap[Incomplete, np.dtype[_ScalarT]]: ...
6767
@overload
6868
def __new__(
69-
cls,
69+
subtype,
7070
filename: _ToFileName,
7171
dtype: npt.DTypeLike,
7272
mode: _ToMode = "r+",

src/numpy-stubs/_core/records.pyi

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from _typeshed import StrOrBytesPath
22
from collections.abc import Iterable, Sequence
3-
from typing import IO, Any, Literal, Protocol, SupportsIndex, TypeAlias, overload, type_check_only
3+
from typing import IO, Any, ClassVar, Literal as L, Protocol, SupportsIndex, TypeAlias, overload, type_check_only
44
from typing_extensions import TypeVar
55

66
import numpy as np
7+
from numpy import _ByteOrder, _OrderKACF, _SupportsBuffer # noqa: ICN003
78
from numpy._typing import ArrayLike, DTypeLike, NDArray, _ArrayLikeVoid_co, _NestedSequence, _ShapeLike
89

910
__all__ = [
@@ -43,10 +44,13 @@ class format_parser:
4344
names: str | Sequence[str] | None,
4445
titles: str | Sequence[str] | None,
4546
aligned: bool = False,
46-
byteorder: np._ByteOrder | None = None,
47+
byteorder: _ByteOrder | None = None,
4748
) -> None: ...
4849

4950
class record(np.void): # type: ignore[misc]
51+
__name__: ClassVar[L["record"]] = "record"
52+
__module__: L["numpy"] = "numpy"
53+
5054
def pprint(self) -> str: ...
5155
def __getattribute__(self, attr: str, /) -> Any: ...
5256
def __setattr__(self, attr: str, val: ArrayLike, /) -> None: ...
@@ -59,42 +63,44 @@ class record(np.void): # type: ignore[misc]
5963
class recarray(np.ndarray[_ShapeT_co, _DTypeT_co]):
6064
@overload
6165
def __new__(
62-
cls,
66+
subtype,
6367
shape: _ShapeLike,
6468
dtype: None = None,
65-
buf: np._SupportsBuffer | None = None,
69+
buf: _SupportsBuffer | None = None,
6670
offset: SupportsIndex = 0,
6771
strides: _ShapeLike | None = None,
6872
*,
6973
formats: DTypeLike,
7074
names: str | Sequence[str] | None = None,
7175
titles: str | Sequence[str] | None = None,
72-
byteorder: np._ByteOrder | None = None,
76+
byteorder: _ByteOrder | None = None,
7377
aligned: bool = False,
74-
order: np._OrderKACF = "C",
78+
order: _OrderKACF = "C",
7579
) -> _RecArray[record]: ...
7680
@overload
7781
def __new__(
78-
cls,
82+
subtype,
7983
shape: _ShapeLike,
8084
dtype: DTypeLike,
81-
buf: np._SupportsBuffer | None = None,
85+
buf: _SupportsBuffer | None = None,
8286
offset: SupportsIndex = ...,
8387
strides: _ShapeLike | None = None,
8488
formats: None = None,
8589
names: None = None,
8690
titles: None = None,
8791
byteorder: None = None,
88-
aligned: Literal[False] = False,
89-
order: np._OrderKACF = "C",
92+
aligned: L[False] = False,
93+
order: _OrderKACF = "C",
9094
) -> _RecArray[Any]: ...
91-
def __getattr__(self, attr: str, /) -> Any: ...
95+
def __getattribute__(self, attr: str, /) -> Any: ...
9296
def __setattr__(self, attr: str, val: ArrayLike, /) -> None: ...
9397
def __array_finalize__(self, /, obj: object) -> None: ...
94-
@overload
95-
def field(self, /, attr: int | str, val: None = None) -> Any: ...
98+
99+
#
96100
@overload
97101
def field(self, /, attr: int | str, val: ArrayLike) -> None: ...
102+
@overload
103+
def field(self, /, attr: int | str, val: None = None) -> Any: ...
98104

99105
# exported in `numpy.rec`
100106
def find_duplicate(list: Iterable[_T]) -> list[_T]: ...
@@ -121,7 +127,7 @@ def fromarrays(
121127
names: str | Sequence[str] | None = None,
122128
titles: str | Sequence[str] | None = None,
123129
aligned: bool = False,
124-
byteorder: np._ByteOrder | None = None,
130+
byteorder: _ByteOrder | None = None,
125131
) -> _RecArray[record]: ...
126132

127133
# exported in `numpy.rec`
@@ -146,13 +152,13 @@ def fromrecords(
146152
names: str | Sequence[str] | None = None,
147153
titles: str | Sequence[str] | None = None,
148154
aligned: bool = False,
149-
byteorder: np._ByteOrder | None = None,
155+
byteorder: _ByteOrder | None = None,
150156
) -> _RecArray[record]: ...
151157

152158
# exported in `numpy.rec`
153159
@overload
154160
def fromstring(
155-
datastring: np._SupportsBuffer,
161+
datastring: _SupportsBuffer,
156162
dtype: DTypeLike,
157163
shape: _ShapeLike | None = None,
158164
offset: int = 0,
@@ -164,7 +170,7 @@ def fromstring(
164170
) -> _RecArray[record]: ...
165171
@overload
166172
def fromstring(
167-
datastring: np._SupportsBuffer,
173+
datastring: _SupportsBuffer,
168174
dtype: None = None,
169175
shape: _ShapeLike | None = None,
170176
offset: int = 0,
@@ -173,7 +179,7 @@ def fromstring(
173179
names: str | Sequence[str] | None = None,
174180
titles: str | Sequence[str] | None = None,
175181
aligned: bool = False,
176-
byteorder: np._ByteOrder | None = None,
182+
byteorder: _ByteOrder | None = None,
177183
) -> _RecArray[record]: ...
178184

179185
#
@@ -203,7 +209,7 @@ def fromfile(
203209
names: str | Sequence[str] | None = None,
204210
titles: str | Sequence[str] | None = None,
205211
aligned: bool = False,
206-
byteorder: np._ByteOrder | None = None,
212+
byteorder: _ByteOrder | None = None,
207213
) -> _RecArray[record]: ...
208214

209215
# exported in `numpy.rec`
@@ -213,6 +219,7 @@ def array(
213219
dtype: None = None,
214220
shape: _ShapeLike | None = None,
215221
offset: int = 0,
222+
strides: tuple[int, ...] | None = None,
216223
formats: None = None,
217224
names: None = None,
218225
titles: None = None,
@@ -226,6 +233,7 @@ def array(
226233
dtype: DTypeLike,
227234
shape: _ShapeLike | None = None,
228235
offset: int = 0,
236+
strides: tuple[int, ...] | None = None,
229237
formats: None = None,
230238
names: None = None,
231239
titles: None = None,
@@ -239,12 +247,13 @@ def array(
239247
dtype: None = None,
240248
shape: _ShapeLike | None = None,
241249
offset: int = 0,
250+
strides: tuple[int, ...] | None = None,
242251
*,
243252
formats: DTypeLike,
244253
names: str | Sequence[str] | None = None,
245254
titles: str | Sequence[str] | None = None,
246255
aligned: bool = False,
247-
byteorder: np._ByteOrder | None = None,
256+
byteorder: _ByteOrder | None = None,
248257
copy: bool = True,
249258
) -> _RecArray[record]: ...
250259
@overload
@@ -253,6 +262,7 @@ def array(
253262
dtype: DTypeLike,
254263
shape: _ShapeLike,
255264
offset: int = 0,
265+
strides: tuple[int, ...] | None = None,
256266
formats: None = None,
257267
names: None = None,
258268
titles: None = None,
@@ -267,11 +277,12 @@ def array(
267277
*,
268278
shape: _ShapeLike,
269279
offset: int = 0,
280+
strides: tuple[int, ...] | None = None,
270281
formats: DTypeLike,
271282
names: str | Sequence[str] | None = None,
272283
titles: str | Sequence[str] | None = None,
273284
aligned: bool = False,
274-
byteorder: np._ByteOrder | None = None,
285+
byteorder: _ByteOrder | None = None,
275286
copy: bool = True,
276287
) -> _RecArray[record]: ...
277288
@overload
@@ -280,6 +291,7 @@ def array(
280291
dtype: DTypeLike,
281292
shape: _ShapeLike | None = None,
282293
offset: int = 0,
294+
strides: tuple[int, ...] | None = None,
283295
formats: None = None,
284296
names: None = None,
285297
titles: None = None,
@@ -293,11 +305,12 @@ def array(
293305
dtype: None = None,
294306
shape: _ShapeLike | None = None,
295307
offset: int = 0,
308+
strides: tuple[int, ...] | None = None,
296309
*,
297310
formats: DTypeLike,
298311
names: str | Sequence[str] | None = None,
299312
titles: str | Sequence[str] | None = None,
300313
aligned: bool = False,
301-
byteorder: np._ByteOrder | None = None,
314+
byteorder: _ByteOrder | None = None,
302315
copy: bool = True,
303316
) -> _RecArray[record]: ...

0 commit comments

Comments
 (0)