summaryrefslogtreecommitdiff
path: root/numpy/_array_api
diff options
context:
space:
mode:
authorAaron Meurer <asmeurer@gmail.com>2021-07-09 16:28:13 -0600
committerAaron Meurer <asmeurer@gmail.com>2021-07-09 16:28:13 -0600
commitc5999e2163f06bb9316dab03d0e1b2173e78bb65 (patch)
treed720e5b3b2fd67877510fd5b21c422c068d55281 /numpy/_array_api
parent5febef530e055572fd5eac18807675ee451c81b0 (diff)
downloadnumpy-c5999e2163f06bb9316dab03d0e1b2173e78bb65.tar.gz
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.
Diffstat (limited to 'numpy/_array_api')
-rw-r--r--numpy/_array_api/_array_object.py16
1 files changed, 10 insertions, 6 deletions
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__.
"""