From c5999e2163f06bb9316dab03d0e1b2173e78bb65 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Fri, 9 Jul 2021 16:28:13 -0600 Subject: Update the type hints for the array API __pow__ and __truediv__ They should not accept int. PEP 484 actually makes int a subtype of float, so this won't actually affect type checkers the way we would want. --- numpy/_array_api/_array_object.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 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 797f9ea4f..a58063698 100644 --- a/numpy/_array_api/_array_object.py +++ b/numpy/_array_api/_array_object.py @@ -494,8 +494,10 @@ class Array: res = self._array.__pos__() return self.__class__._new(res) + # PEP 484 requires int to be a subtype of float, but __pow__ should not + # accept int. @np.errstate(all='ignore') - def __pow__(self: Array, other: Union[int, float, Array], /) -> Array: + def __pow__(self: Array, other: Union[float, Array], /) -> Array: """ Performs the operation __pow__. """ @@ -543,8 +545,10 @@ class Array: res = self._array.__sub__(other._array) return self.__class__._new(res) + # PEP 484 requires int to be a subtype of float, but __truediv__ should + # not accept int. @np.errstate(all='ignore') - def __truediv__(self: Array, other: Union[int, float, Array], /) -> Array: + def __truediv__(self: Array, other: Union[float, Array], /) -> Array: """ Performs the operation __truediv__. """ @@ -742,7 +746,7 @@ class Array: return self.__class__._new(res) @np.errstate(all='ignore') - def __ipow__(self: Array, other: Union[int, float, Array], /) -> Array: + def __ipow__(self: Array, other: Union[float, Array], /) -> Array: """ Performs the operation __ipow__. """ @@ -754,7 +758,7 @@ class Array: return self @np.errstate(all='ignore') - def __rpow__(self: Array, other: Union[int, float, Array], /) -> Array: + def __rpow__(self: Array, other: Union[float, Array], /) -> Array: """ Performs the operation __rpow__. """ @@ -812,7 +816,7 @@ class Array: return self.__class__._new(res) @np.errstate(all='ignore') - def __itruediv__(self: Array, other: Union[int, float, Array], /) -> Array: + def __itruediv__(self: Array, other: Union[float, Array], /) -> Array: """ Performs the operation __itruediv__. """ @@ -824,7 +828,7 @@ class Array: return self @np.errstate(all='ignore') - def __rtruediv__(self: Array, other: Union[int, float, Array], /) -> Array: + def __rtruediv__(self: Array, other: Union[float, Array], /) -> Array: """ Performs the operation __rtruediv__. """ -- cgit v1.2.1