Skip to content

TYP: fix signatures of ndarray.put and ndarray.view #28508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions numpy/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,11 @@ class _HasShape(Protocol[_ShapeT_co]):
@property
def shape(self, /) -> _ShapeT_co: ...

@type_check_only
class _HasDType(Protocol[_T_co]):
@property
def dtype(self, /) -> _T_co: ...

@type_check_only
class _HasShapeAndSupportsItem(_HasShape[_ShapeT_co], _SupportsItem[_T_co], Protocol[_ShapeT_co, _T_co]): ...

Expand Down Expand Up @@ -2339,12 +2344,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]):

# `put` is technically available to `generic`,
# but is pointless as `generic`s are immutable
def put(
self,
ind: _ArrayLikeInt_co,
v: ArrayLike,
mode: _ModeKind = ...,
) -> None: ...
def put(self, /, indices: _ArrayLikeInt_co, values: ArrayLike, mode: _ModeKind = "raise") -> None: ...

@overload
def searchsorted( # type: ignore[misc]
Expand Down Expand Up @@ -2531,20 +2531,21 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]):
copy: builtins.bool | _CopyMode = ...,
) -> ndarray[_ShapeT_co, dtype[Any]]: ...

@overload
def view(self) -> Self: ...
@overload
def view(self, type: type[_ArrayT]) -> _ArrayT: ...
@overload
def view(self, dtype: _DTypeLike[_SCT]) -> NDArray[_SCT]: ...
@overload
def view(self, dtype: DTypeLike) -> NDArray[Any]: ...
@overload
def view(
self,
dtype: DTypeLike,
type: type[_ArrayT],
) -> _ArrayT: ...
#
@overload # ()
def view(self, /) -> Self: ...
@overload # (dtype: T)
def view(self, /, dtype: _DType | _HasDType[_DType]) -> ndarray[_ShapeT_co, _DType]: ...
@overload # (dtype: dtype[T])
def view(self, /, dtype: _DTypeLike[_SCT]) -> NDArray[_SCT]: ...
@overload # (type: T)
def view(self, /, *, type: type[_ArrayT]) -> _ArrayT: ...
@overload # (_: T)
def view(self, /, dtype: type[_ArrayT]) -> _ArrayT: ...
@overload # (dtype: ?)
def view(self, /, dtype: DTypeLike) -> ndarray[_ShapeT_co, dtype[Any]]: ...
@overload # (dtype: ?, type: type[T])
def view(self, /, dtype: DTypeLike, type: type[_ArrayT]) -> _ArrayT: ...

@overload
def getfield(
Expand Down
Loading