Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0c002e4

Browse files
committed
TYP: fix remaining stubtest errors in numpy._core
Ported from numpy/numtype#246
1 parent 72d1a72 commit 0c002e4

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

numpy/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5124,7 +5124,7 @@ class memmap(ndarray[_ShapeT_co, _DType_co]):
51245124
def __new__(
51255125
subtype,
51265126
filename: StrOrBytesPath | _SupportsFileMethodsRW,
5127-
dtype: type[uint8] = ...,
5127+
dtype: type[uint8] = ...,buf: _SupportsBuffer | None = None,
51285128
mode: _MemMapModeKind = ...,
51295129
offset: int = ...,
51305130
shape: None | int | tuple[int, ...] = ...,

numpy/_core/multiarray.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,8 @@ class _ConstructorEmpty(Protocol):
355355
**kwargs: Unpack[_KwargsEmpty],
356356
) -> NDArray[Any]: ...
357357

358-
error: Final = Exception
358+
# using `Final` or `TypeAlias` will break stubtest
359+
error = Exception
359360

360361
# from ._multiarray_umath
361362
ITEM_HASOBJECT: Final = 1

numpy/_core/records.pyi

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# ruff: noqa: ANN401
22
# pyright: reportSelfClsParameterName=false
33
from collections.abc import Iterable, Sequence
4-
from types import EllipsisType
5-
from typing import Any, Literal, Protocol, SupportsIndex, TypeAlias, TypeVar, overload, type_check_only
4+
from typing import Any, ClassVar, Literal, Protocol, SupportsIndex, TypeAlias, overload, type_check_only
65

76
from _typeshed import StrOrBytesPath
7+
from typing_extensions import TypeVar
88

9-
from numpy import _ByteOrder, _OrderKACF, _SupportsBuffer, dtype, generic, ndarray, void
9+
import numpy as np
10+
from numpy import _ByteOrder, _OrderKACF, _SupportsBuffer
1011
from numpy._typing import ArrayLike, DTypeLike, NDArray, _ArrayLikeVoid_co, _NestedSequence, _ShapeLike
1112

1213
__all__ = [
@@ -22,11 +23,11 @@ __all__ = [
2223
]
2324

2425
_T = TypeVar("_T")
25-
_SCT = TypeVar("_SCT", bound=generic)
26-
_DType_co = TypeVar("_DType_co", bound=dtype[Any], covariant=True)
26+
_SCT = TypeVar("_SCT", bound=np.generic)
27+
_DTypeT_co = TypeVar("_DTypeT_co", bound=np.dtype[Any], covariant=True)
2728
_ShapeT_co = TypeVar("_ShapeT_co", bound=tuple[int, ...], covariant=True)
2829

29-
_RecArray: TypeAlias = recarray[Any, dtype[_SCT]]
30+
_RecArray: TypeAlias = recarray[Any, np.dtype[_SCT]]
3031

3132
@type_check_only
3233
class _SupportsReadInto(Protocol):
@@ -37,7 +38,7 @@ class _SupportsReadInto(Protocol):
3738
###
3839

3940
# exported in `numpy.rec`
40-
class record(void):
41+
class record(np.void):
4142
def __getattribute__(self, attr: str) -> Any: ...
4243
def __setattr__(self, attr: str, val: ArrayLike) -> None: ...
4344
def pprint(self) -> str: ...
@@ -47,10 +48,9 @@ class record(void):
4748
def __getitem__(self, key: list[str]) -> record: ...
4849

4950
# exported in `numpy.rec`
50-
class recarray(ndarray[_ShapeT_co, _DType_co]):
51-
# NOTE: While not strictly mandatory, we're demanding here that arguments
52-
# for the `format_parser`- and `dtype`-based dtype constructors are
53-
# mutually exclusive
51+
class recarray(np.ndarray[_ShapeT_co, _DTypeT_co]):
52+
__name__: ClassVar[Literal["record"]] = "record"
53+
__module__: Literal["numpy"] = "numpy"
5454
@overload
5555
def __new__(
5656
subtype,
@@ -66,7 +66,7 @@ class recarray(ndarray[_ShapeT_co, _DType_co]):
6666
byteorder: _ByteOrder | None = None,
6767
aligned: bool = False,
6868
order: _OrderKACF = "C",
69-
) -> recarray[Any, dtype[record]]: ...
69+
) -> _RecArray[record]: ...
7070
@overload
7171
def __new__(
7272
subtype,
@@ -81,18 +81,20 @@ class recarray(ndarray[_ShapeT_co, _DType_co]):
8181
byteorder: None = None,
8282
aligned: Literal[False] = False,
8383
order: _OrderKACF = "C",
84-
) -> recarray[Any, dtype[Any]]: ...
84+
) -> _RecArray[Any]: ...
8585
def __array_finalize__(self, /, obj: object) -> None: ...
8686
def __getattribute__(self, attr: str, /) -> Any: ...
8787
def __setattr__(self, attr: str, val: ArrayLike, /) -> None: ...
88-
@overload
89-
def field(self, /, attr: int | str, val: None = None) -> Any: ...
88+
89+
#
9090
@overload
9191
def field(self, /, attr: int | str, val: ArrayLike) -> None: ...
92+
@overload
93+
def field(self, /, attr: int | str, val: None = None) -> Any: ...
9294

9395
# exported in `numpy.rec`
9496
class format_parser:
95-
dtype: dtype[void]
97+
dtype: np.dtype[np.void]
9698
def __init__(
9799
self,
98100
/,
@@ -213,6 +215,7 @@ def array(
213215
dtype: None = None,
214216
shape: _ShapeLike | None = None,
215217
offset: int = 0,
218+
strides: tuple[int, ...] | None = None,
216219
formats: None = None,
217220
names: None = None,
218221
titles: None = None,
@@ -226,6 +229,7 @@ def array(
226229
dtype: DTypeLike,
227230
shape: _ShapeLike | None = None,
228231
offset: int = 0,
232+
strides: tuple[int, ...] | None = None,
229233
formats: None = None,
230234
names: None = None,
231235
titles: None = None,
@@ -239,6 +243,7 @@ def array(
239243
dtype: None = None,
240244
shape: _ShapeLike | None = None,
241245
offset: int = 0,
246+
strides: tuple[int, ...] | None = None,
242247
*,
243248
formats: DTypeLike,
244249
names: str | Sequence[str] | None = None,
@@ -253,6 +258,7 @@ def array(
253258
dtype: DTypeLike,
254259
shape: _ShapeLike,
255260
offset: int = 0,
261+
strides: tuple[int, ...] | None = None,
256262
formats: None = None,
257263
names: None = None,
258264
titles: None = None,
@@ -267,6 +273,7 @@ def array(
267273
*,
268274
shape: _ShapeLike,
269275
offset: int = 0,
276+
strides: tuple[int, ...] | None = None,
270277
formats: DTypeLike,
271278
names: str | Sequence[str] | None = None,
272279
titles: str | Sequence[str] | None = None,
@@ -280,6 +287,7 @@ def array(
280287
dtype: DTypeLike,
281288
shape: _ShapeLike | None = None,
282289
offset: int = 0,
290+
strides: tuple[int, ...] | None = None,
283291
formats: None = None,
284292
names: None = None,
285293
titles: None = None,
@@ -293,6 +301,7 @@ def array(
293301
dtype: None = None,
294302
shape: _ShapeLike | None = None,
295303
offset: int = 0,
304+
strides: tuple[int, ...] | None = None,
296305
*,
297306
formats: DTypeLike,
298307
names: str | Sequence[str] | None = None,

0 commit comments

Comments
 (0)