|
1 | 1 | import builtins
|
2 | 2 | import sys
|
3 |
| -import os |
4 | 3 | import mmap
|
5 | 4 | import ctypes as ct
|
6 | 5 | import array as _array
|
@@ -210,7 +209,7 @@ from typing import (
|
210 | 209 | # library include `typing_extensions` stubs:
|
211 | 210 | # https://github.com/python/typeshed/blob/main/stdlib/typing_extensions.pyi
|
212 | 211 | from _typeshed import StrOrBytesPath, SupportsFlush, SupportsLenAndGetItem, SupportsWrite
|
213 |
| -from typing_extensions import CapsuleType, Generic, LiteralString, Protocol, Self, TypeVar, Unpack, deprecated, overload |
| 212 | +from typing_extensions import CapsuleType, Generic, LiteralString, Never, Protocol, Self, TypeVar, Unpack, deprecated, overload |
214 | 213 |
|
215 | 214 | from numpy import (
|
216 | 215 | core,
|
@@ -1757,11 +1756,11 @@ _IntegralArrayT = TypeVar("_IntegralArrayT", bound=NDArray[integer[Any] | np.boo
|
1757 | 1756 | _RealArrayT = TypeVar("_RealArrayT", bound=NDArray[floating[Any] | integer[Any] | timedelta64 | np.bool | object_])
|
1758 | 1757 | _NumericArrayT = TypeVar("_NumericArrayT", bound=NDArray[number[Any] | timedelta64 | object_])
|
1759 | 1758 |
|
1760 |
| -_Shape1D: TypeAlias = tuple[int] |
1761 | 1759 | _Shape2D: TypeAlias = tuple[int, int]
|
1762 | 1760 |
|
1763 | 1761 | _ShapeType = TypeVar("_ShapeType", bound=_Shape)
|
1764 | 1762 | _ShapeType_co = TypeVar("_ShapeType_co", covariant=True, bound=_Shape)
|
| 1763 | +_Shape1NType = TypeVar("_Shape1NType", bound=tuple[L[1], Unpack[tuple[L[1], ...]]]) # (1,) | (1, 1) | (1, 1, 1) | ... |
1765 | 1764 | _Shape2DType_co = TypeVar("_Shape2DType_co", covariant=True, bound=_Shape2D)
|
1766 | 1765 | _NumberType = TypeVar("_NumberType", bound=number[Any])
|
1767 | 1766 |
|
@@ -3204,10 +3203,88 @@ class generic(_ArrayOrScalarCommon):
|
3204 | 3203 | def flatten(self, order: _OrderKACF = ...) -> NDArray[Self]: ...
|
3205 | 3204 | def ravel(self, order: _OrderKACF = ...) -> NDArray[Self]: ...
|
3206 | 3205 |
|
3207 |
| - @overload |
3208 |
| - def reshape(self, shape: _ShapeLike, /, *, order: _OrderACF = ...) -> NDArray[Self]: ... |
3209 |
| - @overload |
3210 |
| - def reshape(self, *shape: SupportsIndex, order: _OrderACF = ...) -> NDArray[Self]: ... |
| 3206 | + @overload # (() | []) |
| 3207 | + def reshape( |
| 3208 | + self, |
| 3209 | + shape: tuple[()] | list[Never], |
| 3210 | + /, |
| 3211 | + *, |
| 3212 | + order: _OrderACF = "C", |
| 3213 | + copy: builtins.bool | None = None, |
| 3214 | + ) -> Self: ... |
| 3215 | + @overload # ((1, *(1, ...))@_ShapeType) |
| 3216 | + def reshape( |
| 3217 | + self, |
| 3218 | + shape: _Shape1NType, |
| 3219 | + /, |
| 3220 | + *, |
| 3221 | + order: _OrderACF = "C", |
| 3222 | + copy: builtins.bool | None = None, |
| 3223 | + ) -> ndarray[_Shape1NType, dtype[Self]]: ... |
| 3224 | + @overload # (Sequence[index, ...]) # not recommended |
| 3225 | + def reshape( |
| 3226 | + self, |
| 3227 | + shape: Sequence[SupportsIndex], |
| 3228 | + /, |
| 3229 | + *, |
| 3230 | + order: _OrderACF = "C", |
| 3231 | + copy: builtins.bool | None = None, |
| 3232 | + ) -> Self | ndarray[tuple[L[1], ...], dtype[Self]]: ... |
| 3233 | + @overload # _(index) |
| 3234 | + def reshape( |
| 3235 | + self, |
| 3236 | + size1: SupportsIndex, |
| 3237 | + /, |
| 3238 | + *, |
| 3239 | + order: _OrderACF = "C", |
| 3240 | + copy: builtins.bool | None = None, |
| 3241 | + ) -> ndarray[tuple[L[1]], dtype[Self]]: ... |
| 3242 | + @overload # _(index, index) |
| 3243 | + def reshape( |
| 3244 | + self, |
| 3245 | + size1: SupportsIndex, |
| 3246 | + size2: SupportsIndex, |
| 3247 | + /, |
| 3248 | + *, |
| 3249 | + order: _OrderACF = "C", |
| 3250 | + copy: builtins.bool | None = None, |
| 3251 | + ) -> ndarray[tuple[L[1], L[1]], dtype[Self]]: ... |
| 3252 | + @overload # _(index, index, index) |
| 3253 | + def reshape( |
| 3254 | + self, |
| 3255 | + size1: SupportsIndex, |
| 3256 | + size2: SupportsIndex, |
| 3257 | + size3: SupportsIndex, |
| 3258 | + /, |
| 3259 | + *, |
| 3260 | + order: _OrderACF = "C", |
| 3261 | + copy: builtins.bool | None = None, |
| 3262 | + ) -> ndarray[tuple[L[1], L[1], L[1]], dtype[Self]]: ... |
| 3263 | + @overload # _(index, index, index, index) |
| 3264 | + def reshape( |
| 3265 | + self, |
| 3266 | + size1: SupportsIndex, |
| 3267 | + size2: SupportsIndex, |
| 3268 | + size3: SupportsIndex, |
| 3269 | + size4: SupportsIndex, |
| 3270 | + /, |
| 3271 | + *, |
| 3272 | + order: _OrderACF = "C", |
| 3273 | + copy: builtins.bool | None = None, |
| 3274 | + ) -> ndarray[tuple[L[1], L[1], L[1], L[1]], dtype[Self]]: ... |
| 3275 | + @overload # _(index, index, index, index, index, *index) # ndim >= 5 |
| 3276 | + def reshape( |
| 3277 | + self, |
| 3278 | + size1: SupportsIndex, |
| 3279 | + size2: SupportsIndex, |
| 3280 | + size3: SupportsIndex, |
| 3281 | + size4: SupportsIndex, |
| 3282 | + size5: SupportsIndex, |
| 3283 | + /, |
| 3284 | + *sizes6_: SupportsIndex, |
| 3285 | + order: _OrderACF = "C", |
| 3286 | + copy: builtins.bool | None = None, |
| 3287 | + ) -> ndarray[tuple[L[1], L[1], L[1], L[1], L[1], Unpack[tuple[L[1], ...]]], dtype[Self]]: ... |
3211 | 3288 |
|
3212 | 3289 | def squeeze(self, axis: None | L[0] | tuple[()] = ...) -> Self: ...
|
3213 | 3290 | def transpose(self, axes: None | tuple[()] = ..., /) -> Self: ...
|
|
0 commit comments