Skip to content

Commit a7c09a3

Browse files
author
Bas van Beek
committed
ENH: Add annotations for __array_priority__, __array_wrap__ and __array_prepare__
1 parent 1d82bcb commit a7c09a3

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

numpy/__init__.pyi

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,10 +1204,9 @@ class _ArrayOrScalarCommon:
12041204
@property
12051205
def __array_interface__(self): ...
12061206
@property
1207-
def __array_priority__(self): ...
1207+
def __array_priority__(self) -> float: ...
12081208
@property
12091209
def __array_struct__(self): ...
1210-
def __array_wrap__(array, context=...): ...
12111210
def __setstate__(self, __state): ...
12121211
# a `bool_` is returned when `keepdims=True` and `self` is a 0d array
12131212

@@ -1584,6 +1583,7 @@ _FlexDType = TypeVar("_FlexDType", bound=dtype[flexible])
15841583
# TODO: Set the `bound` to something more suitable once we
15851584
# have proper shape support
15861585
_ShapeType = TypeVar("_ShapeType", bound=Any)
1586+
_ShapeType2 = TypeVar("_ShapeType2", bound=Any)
15871587
_NumberType = TypeVar("_NumberType", bound=number[Any])
15881588

15891589
# There is currently no exhaustive way to type the buffer protocol,
@@ -1659,6 +1659,19 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
16591659
def __array__(self, __dtype: None = ...) -> ndarray[Any, _DType_co]: ...
16601660
@overload
16611661
def __array__(self, __dtype: _DType) -> ndarray[Any, _DType]: ...
1662+
1663+
def __array_wrap__(
1664+
self,
1665+
__array: ndarray[_ShapeType2, _DType],
1666+
__context: None | Tuple[ufunc, Tuple[Any, ...], int] = ...,
1667+
) -> ndarray[_ShapeType2, _DType]: ...
1668+
1669+
def __array_prepare__(
1670+
self,
1671+
__array: ndarray[_ShapeType2, _DType],
1672+
__context: None | Tuple[ufunc, Tuple[Any, ...], int] = ...,
1673+
) -> ndarray[_ShapeType2, _DType]: ...
1674+
16621675
@property
16631676
def ctypes(self) -> _ctypes[int]: ...
16641677
@property

0 commit comments

Comments
 (0)