Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2785b94

Browse filesBrowse files
authored
Merge pull request #28508 from jorenham/numtype/200
TYP: fix signatures of ``ndarray.put`` and ``ndarray.view``
2 parents c3d6548 + 33c19a1 commit 2785b94
Copy full SHA for 2785b94

File tree

1 file changed

+21
-20
lines changed
Filter options

1 file changed

+21
-20
lines changed

‎numpy/__init__.pyi

Copy file name to clipboardExpand all lines: numpy/__init__.pyi
+21-20Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,11 @@ class _HasShape(Protocol[_ShapeT_co]):
10951095
@property
10961096
def shape(self, /) -> _ShapeT_co: ...
10971097

1098+
@type_check_only
1099+
class _HasDType(Protocol[_T_co]):
1100+
@property
1101+
def dtype(self, /) -> _T_co: ...
1102+
10981103
@type_check_only
10991104
class _HasShapeAndSupportsItem(_HasShape[_ShapeT_co], _SupportsItem[_T_co], Protocol[_ShapeT_co, _T_co]): ...
11001105

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

23402345
# `put` is technically available to `generic`,
23412346
# but is pointless as `generic`s are immutable
2342-
def put(
2343-
self,
2344-
ind: _ArrayLikeInt_co,
2345-
v: ArrayLike,
2346-
mode: _ModeKind = ...,
2347-
) -> None: ...
2347+
def put(self, /, indices: _ArrayLikeInt_co, values: ArrayLike, mode: _ModeKind = "raise") -> None: ...
23482348

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

2534-
@overload
2535-
def view(self) -> Self: ...
2536-
@overload
2537-
def view(self, type: type[_ArrayT]) -> _ArrayT: ...
2538-
@overload
2539-
def view(self, dtype: _DTypeLike[_SCT]) -> NDArray[_SCT]: ...
2540-
@overload
2541-
def view(self, dtype: DTypeLike) -> NDArray[Any]: ...
2542-
@overload
2543-
def view(
2544-
self,
2545-
dtype: DTypeLike,
2546-
type: type[_ArrayT],
2547-
) -> _ArrayT: ...
2534+
#
2535+
@overload # ()
2536+
def view(self, /) -> Self: ...
2537+
@overload # (dtype: T)
2538+
def view(self, /, dtype: _DType | _HasDType[_DType]) -> ndarray[_ShapeT_co, _DType]: ...
2539+
@overload # (dtype: dtype[T])
2540+
def view(self, /, dtype: _DTypeLike[_SCT]) -> NDArray[_SCT]: ...
2541+
@overload # (type: T)
2542+
def view(self, /, *, type: type[_ArrayT]) -> _ArrayT: ...
2543+
@overload # (_: T)
2544+
def view(self, /, dtype: type[_ArrayT]) -> _ArrayT: ...
2545+
@overload # (dtype: ?)
2546+
def view(self, /, dtype: DTypeLike) -> ndarray[_ShapeT_co, dtype[Any]]: ...
2547+
@overload # (dtype: ?, type: type[T])
2548+
def view(self, /, dtype: DTypeLike, type: type[_ArrayT]) -> _ArrayT: ...
25482549

25492550
@overload
25502551
def getfield(

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.