From 74478e2d943f4d61917d4d9122a042214eed94fd Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Fri, 9 Jul 2021 13:57:44 -0600 Subject: Use better type signatures in the array API module This includes returning custom dataclasses for finfo and iinfo that only contain the properties required by the array API specification. --- numpy/_array_api/_array_object.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'numpy/_array_api/_array_object.py') diff --git a/numpy/_array_api/_array_object.py b/numpy/_array_api/_array_object.py index 9ea0eef18..43d8a8961 100644 --- a/numpy/_array_api/_array_object.py +++ b/numpy/_array_api/_array_object.py @@ -396,7 +396,8 @@ class Array: res = self._array.__le__(other._array) return self.__class__._new(res) - def __len__(self, /): + # Note: __len__ may end up being removed from the array API spec. + def __len__(self, /) -> int: """ Performs the operation __len__. """ @@ -843,7 +844,7 @@ class Array: return self.__class__._new(res) @property - def dtype(self): + def dtype(self) -> Dtype: """ Array API compatible wrapper for :py:meth:`np.ndaray.dtype `. @@ -852,7 +853,7 @@ class Array: return self._array.dtype @property - def device(self): + def device(self) -> Device: """ Array API compatible wrapper for :py:meth:`np.ndaray.device `. @@ -862,7 +863,7 @@ class Array: raise NotImplementedError("The device attribute is not yet implemented") @property - def ndim(self): + def ndim(self) -> int: """ Array API compatible wrapper for :py:meth:`np.ndaray.ndim `. @@ -871,7 +872,7 @@ class Array: return self._array.ndim @property - def shape(self): + def shape(self) -> Tuple[int, ...]: """ Array API compatible wrapper for :py:meth:`np.ndaray.shape `. @@ -880,7 +881,7 @@ class Array: return self._array.shape @property - def size(self): + def size(self) -> int: """ Array API compatible wrapper for :py:meth:`np.ndaray.size `. @@ -889,7 +890,7 @@ class Array: return self._array.size @property - def T(self): + def T(self) -> Array: """ Array API compatible wrapper for :py:meth:`np.ndaray.T `. -- cgit v1.2.1