10000 TYP: Backport typing fixes from main (4) by charris · Pull Request #28542 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

TYP: Backport typing fixes from main (4) #28542

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 7 commits into from
Mar 16, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
TYP: fix typing errors in numpy.ndarray (#28540)
Ported from numpy/numtype#200
  • Loading branch information
jorenham authored and charris committed Mar 16, 2025
commit 110bb8e98d87ea291eb997a748f316bb286ad25b
36 changes: 8 additions & 28 deletions numpy/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2231,11 +2231,9 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]):
@overload
def resize(self, new_shape: _ShapeLike, /, *, refcheck: builtins.bool = ...) -> None: ...
@overload
def resize(self, *new_shape: SupportsIndex, refcheck: builtins.bool = ...) -> None: ...
def resize(self, /, *new_shape: SupportsIndex, refcheck: builtins.bool = ...) -> None: ...

def setflags(
self, write: builtins.bool = ..., align: builtins.bool = ..., uic: builtins.bool = ...
) -> None: ...
def setflags(self, write: builtins.bool = ..., align: builtins.bool = ..., uic: builtins.bool = ...) -> None: ...

def squeeze(
self,
Expand Down Expand Up @@ -2381,13 +2379,6 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]):
sorter: None | _ArrayLikeInt_co = ...,
) -> NDArray[intp]: ...

def setfield(
self,
val: ArrayLike,
dtype: DTypeLike,
offset: SupportsIndex = ...,
) -> None: ...

def sort(
self,
axis: SupportsIndex = ...,
Expand Down Expand Up @@ -2567,23 +2558,14 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]):
@overload # (dtype: ?, type: type[T])
def view(self, /, dtype: DTypeLike, type: type[_ArrayT]) -> _ArrayT: ...

def setfield(self, /, val: ArrayLike, dtype: DTypeLike, offset: CanIndex = 0) -> None: ...
@overload
def getfield(
self,
dtype: _DTypeLike[_SCT],
offset: SupportsIndex = ...
) -> NDArray[_SCT]: ...
def getfield(self, dtype: _DTypeLike[_SCT], offset: SupportsIndex = 0) -> NDArray[_SCT]: ...
@overload
def getfield(
self,
dtype: DTypeLike,
offset: SupportsIndex = ...
) -> NDArray[Any]: ...
def getfield(self, dtype: DTypeLike, offset: SupportsIndex = 0) -> NDArray[Any]: ...

def __index__(self: NDArray[np.integer[Any]], /) -> int: ...
def __int__(self: NDArray[number[Any] | np.timedelta64 | np.bool | object_], /) -> int: ...
def __float__(self: NDArray[number[Any] | np.timedelta64 | np.bool | object_], /) -> float: ...
def __complex__(self: NDArray[number[Any] | np.bool | object_], /) -> complex: ...
def __index__(self: NDArray[integer], /) -> int: ...
def __complex__(self: NDArray[number | np.bool | object_], /) -> complex: ...

def __len__(self) -> int: ...
def __contains__(self, value: object, /) -> builtins.bool: ...
Expand Down Expand Up @@ -2659,9 +2641,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]):
# @overload
# def __abs__(self: ndarray[_ShapeType, dtype[complex128]], /) -> ndarray[_ShapeType, dtype[float64]]: ...
@overload
def __abs__(
self: ndarray[_ShapeT, dtype[complexfloating[_AnyNBitInexact]]], /
) -> ndarray[_ShapeT, dtype[floating[_AnyNBitInexact]]]: ...
def __abs__(self: ndarray[_ShapeT, dtype[complexfloating[_NBit]]], /) -> ndarray[_ShapeT, dtype[floating[_NBit]]]: ...
@overload
def __abs__(self: _RealArrayT, /) -> _RealArrayT: ...

Expand Down
2 changes: 0 additions & 2 deletions numpy/typing/tests/data/fail/ndarray_misc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ f8.setfield(2, np.float64) # E: has no attribute
f8.sort() # E: has no attribute
f8.trace() # E: has no attribute

AR_M.__int__() # E: Invalid self argument
AR_M.__float__() # E: Invalid self argument
AR_M.__complex__() # E: Invalid self argument
AR_b.__index__() # E: Invalid self argument

Expand Down
0