Skip to content

Commit 6932710

Browse files
committed
🩹 some rank-typing fixes in ndarray
1 parent f50c41f commit 6932710

File tree

1 file changed

+19
-28
lines changed

1 file changed

+19
-28
lines changed

‎src/numpy-stubs/__init__.pyi

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,6 @@ _NumericArrayT = TypeVar("_NumericArrayT", bound=NDArray[number | timedelta64 |
630630
_ShapeT = TypeVar("_ShapeT", bound=_nt.Shape)
631631
_ShapeT_co = TypeVar("_ShapeT_co", bound=_nt.Shape, covariant=True)
632632
_ShapeT_1nd = TypeVar("_ShapeT_1nd", bound=_nt.Shape1N)
633-
_1NShapeT = TypeVar("_1NShapeT", bound=tuple[L[1], *tuple[L[1], ...]]) # TODO(jorenham): remove
634633

635634
_ScalarT = TypeVar("_ScalarT", bound=generic)
636635
_SelfScalarT = TypeVar("_SelfScalarT", bound=generic)
@@ -1959,7 +1958,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
19591958
def __array__(self, dtype: _DTypeT, /, *, copy: bool | None = None) -> ndarray[_ShapeT_co, _DTypeT]: ...
19601959

19611960
#
1962-
def __array_finalize__(self, obj: NDArray[Any] | Any, /) -> None: ...
1961+
def __array_finalize__(self, obj: _nt.Array[Any] | Any, /) -> None: ...
19631962
def __array_ufunc__(self, ufunc: ufunc, method: _UFuncMethod, /, *inputs: object, **kwargs: object) -> Any: ...
19641963
def __array_function__(
19651964
self,
@@ -2909,12 +2908,25 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
29092908
@overload
29102909
def resize(self: ndarray[_ShapeT, Any], new_shape: _ShapeT, /, *, refcheck: py_bool = True) -> None: ...
29112910
@overload
2912-
def resize(self: _nt.Array1D[Any], n0: CanIndex, /, *, refcheck: py_bool = True) -> None: ...
2911+
def resize(self: _nt.Array[Any, _nt.Shape1], n0: CanIndex, /, *, refcheck: py_bool = True) -> None: ...
29132912
@overload
2914-
def resize(self: _nt.Array2D[Any], n0: CanIndex, n1: CanIndex, /, *, refcheck: py_bool = True) -> None: ...
2913+
def resize(
2914+
self: _nt.Array[Any, _nt.Shape2], n0: CanIndex, n1: CanIndex, /, *, refcheck: py_bool = True
2915+
) -> None: ...
2916+
@overload
2917+
def resize(
2918+
self: _nt.Array[Any, _nt.Shape3], n0: CanIndex, n1: CanIndex, n2: CanIndex, /, *, refcheck: py_bool = True
2919+
) -> None: ...
29152920
@overload
29162921
def resize(
2917-
self: _nt.Array3D[Any], n0: CanIndex, n1: CanIndex, n2: CanIndex, /, *, refcheck: py_bool = True
2922+
self: _nt.Array[Any, _nt.Shape4],
2923+
n0: CanIndex,
2924+
n1: CanIndex,
2925+
n2: CanIndex,
2926+
n3: CanIndex,
2927+
/,
2928+
*,
2929+
refcheck: py_bool = True,
29182930
) -> None: ...
29192931

29202932
#
@@ -3271,7 +3283,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
32713283

32723284
#
32733285
@overload
3274-
def repeat(self, /, repeats: _nt.CoInteger_nd, axis: None = None) -> ndarray[_nt.Shape1, _DTypeT_co]: ...
3286+
def repeat(self, /, repeats: _nt.CoInteger_nd, axis: None = None) -> ndarray[_nt.Rank1, _DTypeT_co]: ...
32753287
@overload
32763288
def repeat(
32773289
self: ndarray[_AnyShapeT, _DTypeT], /, repeats: _nt.CoInteger_nd, axis: CanIndex
@@ -3719,15 +3731,6 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]):
37193731
order: _OrderACF = "C",
37203732
copy: py_bool | None = None,
37213733
) -> Self: ...
3722-
@overload # ((1, *(1, ...))@_ShapeType)
3723-
def reshape(
3724-
self,
3725-
shape: _1NShapeT,
3726-
/,
3727-
*,
3728-
order: _OrderACF = "C",
3729-
copy: py_bool | None = None,
3730-
) -> ndarray[_1NShapeT, dtype[Self]]: ...
37313734
@overload # (Sequence[index, ...]) # not recommended
37323735
def reshape(
37333736
self,
@@ -3767,18 +3770,6 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]):
37673770
order: _OrderACF = "C",
37683771
copy: py_bool | None = None,
37693772
) -> _nt.Array3D[Self]: ...
3770-
@overload # _(index, index, index, index)
3771-
def reshape(
3772-
self,
3773-
size1: CanIndex,
3774-
size2: CanIndex,
3775-
size3: CanIndex,
3776-
size4: CanIndex,
3777-
/,
3778-
*,
3779-
order: _OrderACF = "C",
3780-
copy: py_bool | None = None,
3781-
) -> _nt.Array4D[Self]: ...
37823773
@overload # _(index, index, index, index, *index) # ndim >= 5
37833774
def reshape(
37843775
self,
@@ -3790,7 +3781,7 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]):
37903781
*sizes5_: CanIndex,
37913782
order: _OrderACF = "C",
37923783
copy: py_bool | None = None,
3793-
) -> _nt.Array[Self, _nt.Shape4N]: ...
3784+
) -> _nt.Array[Self, _nt.Rank4N]: ...
37943785

37953786
#
37963787
@overload

0 commit comments

Comments
 (0)