Skip to content

Commit ed05804

Browse files
committed
🎨 refactor from _numtype import in lib
1 parent 5bc8847 commit ed05804

9 files changed

Lines changed: 1161 additions & 1375 deletions

‎src/numpy-stubs/lib/_arraysetops_impl.pyi‎

Lines changed: 164 additions & 163 deletions
Large diffs are not rendered by default.

‎src/numpy-stubs/lib/_function_base_impl.pyi‎

Lines changed: 427 additions & 458 deletions
Large diffs are not rendered by default.

‎src/numpy-stubs/lib/_index_tricks_impl.pyi‎

Lines changed: 33 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,10 @@
11
from _typeshed import Incomplete
22
from collections.abc import Sequence
3-
from typing import Any, ClassVar, Final, Generic, Literal as L, SupportsIndex, TypeAlias, final, overload
3+
from typing import Any, ClassVar, Final, Generic, Literal as L, SupportsIndex as CanIndex, TypeAlias, final, overload
44
from typing_extensions import Self, TypeVar, deprecated
55

6+
import _numtype as _nt
67
import numpy as np
7-
from _numtype import (
8-
Array,
9-
JustBytes,
10-
JustComplex,
11-
JustFloat,
12-
JustInt,
13-
JustStr,
14-
Sequence1ND,
15-
ToBool_nd,
16-
ToBytes_nd,
17-
ToComplex128_nd,
18-
ToFloat64_nd,
19-
ToInt_nd,
20-
ToObject_nd,
21-
ToStr_nd,
22-
_ToArray_nd,
23-
)
248
from numpy._core.multiarray import ravel_multi_index, unravel_index
259
from numpy._typing import ArrayLike, _SupportsDType as _HasDType
2610

@@ -46,7 +30,7 @@ _DTypeT = TypeVar("_DTypeT", bound=np.dtype)
4630
_ScalarT = TypeVar("_ScalarT", bound=np.generic)
4731
_ScalarT_co = TypeVar("_ScalarT_co", bound=np.generic, default=Any, covariant=True)
4832
_TupleT = TypeVar("_TupleT", bound=tuple[object, ...])
49-
_ArrayT = TypeVar("_ArrayT", bound=Array)
33+
_ArrayT = TypeVar("_ArrayT", bound=_nt.Array)
5034

5135
_BoolT_co = TypeVar("_BoolT_co", bound=bool, default=bool, covariant=True)
5236

@@ -55,32 +39,32 @@ _MatrixT_co = TypeVar("_MatrixT_co", bound=bool, default=L[False], covariant=Tru
5539
_NDMinT_co = TypeVar("_NDMinT_co", bound=int, default=L[1], covariant=True)
5640
_Trans1DT_co = TypeVar("_Trans1DT_co", bound=int, default=L[-1], covariant=True)
5741

58-
_Arrays: TypeAlias = tuple[Array[_ScalarT], ...]
42+
_Arrays: TypeAlias = tuple[_nt.Array[_ScalarT], ...]
5943

6044
###
6145

6246
class ndenumerate(Generic[_ScalarT_co]):
6347
@overload
64-
def __init__(self: ndenumerate[_ScalarT], /, arr: _ToArray_nd[_ScalarT]) -> None: ...
48+
def __init__(self: ndenumerate[_ScalarT], /, arr: _nt._ToArray_nd[_ScalarT]) -> None: ...
6549
@overload
66-
def __init__(self: ndenumerate[np.bytes_], /, arr: ToBytes_nd) -> None: ...
50+
def __init__(self: ndenumerate[np.bytes_], /, arr: _nt.ToBytes_nd) -> None: ...
6751
@overload
68-
def __init__(self: ndenumerate[np.str_], /, arr: ToStr_nd) -> None: ...
52+
def __init__(self: ndenumerate[np.str_], /, arr: _nt.ToStr_nd) -> None: ...
6953
@overload
70-
def __init__(self: ndenumerate[np.bool], /, arr: ToBool_nd) -> None: ...
54+
def __init__(self: ndenumerate[np.bool], /, arr: _nt.ToBool_nd) -> None: ...
7155
@overload
72-
def __init__(self: ndenumerate[np.intp], /, arr: ToInt_nd) -> None: ...
56+
def __init__(self: ndenumerate[np.intp], /, arr: _nt.ToInt_nd) -> None: ...
7357
@overload
74-
def __init__(self: ndenumerate[np.float64], /, arr: ToFloat64_nd) -> None: ...
58+
def __init__(self: ndenumerate[np.float64], /, arr: _nt.ToFloat64_nd) -> None: ...
7559
@overload
76-
def __init__(self: ndenumerate[np.complex128], /, arr: ToComplex128_nd) -> None: ...
60+
def __init__(self: ndenumerate[np.complex128], /, arr: _nt.ToComplex128_nd) -> None: ...
7761
@overload
78-
def __init__(self: ndenumerate[np.object_], /, arr: ToObject_nd) -> None: ...
62+
def __init__(self: ndenumerate[np.object_], /, arr: _nt.ToObject_nd) -> None: ...
7963

8064
# The first overload is a (semi-)workaround for a mypy bug (tested with v1.10 and v1.11)
8165
@overload
8266
def __next__(
83-
self: ndenumerate[np.bool | np.number | np.flexible | np.datetime64 | np.timedelta64],
67+
self: ndenumerate[_nt.co_number | np.flexible | np.datetime64 | np.timedelta64],
8468
/,
8569
) -> tuple[tuple[int, ...], _ScalarT_co]: ...
8670
@overload
@@ -93,9 +77,9 @@ class ndenumerate(Generic[_ScalarT_co]):
9377

9478
class ndindex:
9579
@overload
96-
def __init__(self, shape: tuple[SupportsIndex, ...], /) -> None: ...
80+
def __init__(self, shape: tuple[CanIndex, ...], /) -> None: ...
9781
@overload
98-
def __init__(self, /, *shape: SupportsIndex) -> None: ...
82+
def __init__(self, /, *shape: CanIndex) -> None: ...
9983

10084
#
10185
def __iter__(self) -> Self: ...
@@ -107,9 +91,9 @@ class nd_grid(Generic[_BoolT_co]):
10791
sparse: _BoolT_co
10892
def __init__(self, sparse: _BoolT_co = ...) -> None: ...
10993
@overload
110-
def __getitem__(self: nd_grid[L[False]], key: slice | Sequence[slice]) -> Array: ...
94+
def __getitem__(self: nd_grid[L[False]], key: slice | Sequence[slice]) -> _nt.Array: ...
11195
@overload
112-
def __getitem__(self: nd_grid[L[True]], key: slice | Sequence[slice]) -> tuple[Array, ...]: ...
96+
def __getitem__(self: nd_grid[L[True]], key: slice | Sequence[slice]) -> tuple[_nt.Array, ...]: ...
11397

11498
@final
11599
class MGridClass(nd_grid[L[False]]):
@@ -146,13 +130,17 @@ class AxisConcatenator(Generic[_AxisT_co, _MatrixT_co, _NDMinT_co, _Trans1DT_co]
146130
#
147131
@staticmethod
148132
@overload
149-
def concatenate(*a: _ToArray_nd[_ScalarT], axis: SupportsIndex | None = 0, out: None = None) -> Array[_ScalarT]: ...
133+
def concatenate(
134+
*a: _nt._ToArray_nd[_ScalarT],
135+
axis: CanIndex | None = 0,
136+
out: None = None,
137+
) -> _nt.Array[_ScalarT]: ...
150138
@staticmethod
151139
@overload
152-
def concatenate(*a: ArrayLike, axis: SupportsIndex | None = 0, out: _ArrayT) -> _ArrayT: ...
140+
def concatenate(*a: ArrayLike, axis: CanIndex | None = 0, out: _ArrayT) -> _ArrayT: ...
153141
@staticmethod
154142
@overload
155-
def concatenate(*a: ArrayLike, axis: SupportsIndex | None = 0, out: None = None) -> Array: ...
143+
def concatenate(*a: ArrayLike, axis: CanIndex | None = 0, out: None = None) -> _nt.Array: ...
156144

157145
@final
158146
class RClass(AxisConcatenator[L[0], L[False], L[1], L[-1]]):
@@ -176,31 +164,23 @@ class IndexExpression(Generic[_BoolT_co]):
176164
def __getitem__(self, item: _T, /) -> _T | tuple[_T]: ...
177165

178166
@overload
179-
def ix_(
180-
*args: _HasDType[_DTypeT] | Sequence1ND[_HasDType[_DTypeT]],
181-
) -> tuple[np.ndarray[tuple[int, ...], _DTypeT], ...]: ...
167+
def ix_(*args: _nt.SequenceND[_HasDType[_DTypeT]]) -> tuple[np.ndarray[tuple[int, ...], _DTypeT], ...]: ...
182168
@overload
183-
def ix_(*args: bool | Sequence1ND[bool]) -> _Arrays[np.bool]: ...
169+
def ix_(*args: _nt.SequenceND[bool]) -> _Arrays[np.bool]: ...
184170
@overload
185-
def ix_(*args: JustInt | Sequence1ND[JustInt]) -> _Arrays[np.intp]: ...
171+
def ix_(*args: _nt.SequenceND[_nt.JustInt]) -> _Arrays[np.intp]: ...
186172
@overload
187-
def ix_(*args: JustFloat | Sequence1ND[JustFloat]) -> _Arrays[np.float64]: ...
173+
def ix_(*args: _nt.SequenceND[_nt.JustFloat]) -> _Arrays[np.float64]: ...
188174
@overload
189-
def ix_(*args: JustComplex | Sequence1ND[JustComplex]) -> _Arrays[np.complex128]: ...
175+
def ix_(*args: _nt.SequenceND[_nt.JustComplex]) -> _Arrays[np.complex128]: ...
190176
@overload
191-
def ix_(*args: JustBytes | Sequence1ND[JustBytes]) -> _Arrays[np.bytes_]: ...
177+
def ix_(*args: _nt.SequenceND[_nt.JustBytes]) -> _Arrays[np.bytes_]: ...
192178
@overload
193-
def ix_(*args: JustStr | Sequence1ND[JustStr]) -> _Arrays[np.str_]: ...
194-
@overload
195-
def ix_(*args: int | Sequence1ND[int]) -> _Arrays[np.intp | np.bool]: ... # type: ignore[overload-cannot-match] # pyright: ignore[reportOverlappingOverload]
196-
@overload
197-
def ix_(*args: float | Sequence1ND[float]) -> _Arrays[np.float64 | np.intp | np.bool]: ... # type: ignore[overload-cannot-match] # pyright: ignore[reportOverlappingOverload]
198-
@overload
199-
def ix_(*args: complex | Sequence1ND[complex]) -> _Arrays[np.complex128 | np.float64 | np.intp | np.bool]: ... # type: ignore[overload-cannot-match] # pyright: ignore[reportOverlappingOverload]
179+
def ix_(*args: _nt.SequenceND[_nt.JustStr]) -> _Arrays[np.str_]: ...
200180

201181
#
202-
def fill_diagonal(a: Array, val: Any, wrap: bool = ...) -> None: ...
203-
def diag_indices(n: int, ndim: int = ...) -> _Arrays[np.intp]: ...
182+
def fill_diagonal(a: _nt.Array, val: Any, wrap: bool = False) -> None: ...
183+
def diag_indices(n: int, ndim: int = 2) -> _Arrays[np.intp]: ...
204184
def diag_indices_from(arr: ArrayLike) -> _Arrays[np.intp]: ...
205185

206186
###

0 commit comments

Comments
 (0)