From 7f8df89119e0100270e8f2cc7c7298eb07ffe175 Mon Sep 17 00:00:00 2001 From: mhostetter Date: Sat, 14 Oct 2023 10:14:49 -0400 Subject: [PATCH] Remove `other: Self` type annotation If `Self + NDArray` is performed, this prevents `mypy` from falling back to `ndarray.__radd__()`, which has a return type of `NDArray`. This ensures that the arithmetic type is always `Self`. The runtime type checking will ensure valid arguments are passed. --- src/galois/_domains/_array.py | 40 +++++++++++++++++------------------ 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/galois/_domains/_array.py b/src/galois/_domains/_array.py index 533ad47c5..24cee39cf 100644 --- a/src/galois/_domains/_array.py +++ b/src/galois/_domains/_array.py @@ -454,61 +454,61 @@ def astype(self, dtype, order="K", casting="unsafe", subok=True, copy=True): # pylint: disable=useless-super-delegation,no-member - def __add__(self, other: Self) -> Self: + def __add__(self, other: npt.NDArray) -> Self: return super().__add__(other) - def __iadd__(self, other: Self) -> Self: + def __iadd__(self, other: npt.NDArray) -> Self: return super().__iadd__(other) - def __radd__(self, other: Self) -> Self: + def __radd__(self, other: npt.NDArray) -> Self: return super().__radd__(other) - def __sub__(self, other: Self) -> Self: + def __sub__(self, other: npt.NDArray) -> Self: return super().__sub__(other) - def __isub__(self, other: Self) -> Self: + def __isub__(self, other: npt.NDArray) -> Self: return super().__isub__(other) - def __rsub__(self, other: Self) -> Self: + def __rsub__(self, other: npt.NDArray) -> Self: return super().__rsub__(other) - def __mul__(self, other: int | npt.NDArray | Self) -> Self: + def __mul__(self, other: int | npt.NDArray) -> Self: return super().__mul__(other) - def __imul__(self, other: int | npt.NDArray | Self) -> Self: + def __imul__(self, other: int | npt.NDArray) -> Self: return super().__imul__(other) - def __rmul__(self, other: int | npt.NDArray | Self) -> Self: + def __rmul__(self, other: int | npt.NDArray) -> Self: return super().__rmul__(other) - def __truediv__(self, other: Self) -> Self: + def __truediv__(self, other: npt.NDArray) -> Self: return super().__truediv__(other) - def __itruediv__(self, other: Self) -> Self: + def __itruediv__(self, other: npt.NDArray) -> Self: return super().__itruediv__(other) - def __rtruediv__(self, other: Self) -> Self: + def __rtruediv__(self, other: npt.NDArray) -> Self: return super().__rtruediv__(other) - def __floordiv__(self, other: Self) -> Self: + def __floordiv__(self, other: npt.NDArray) -> Self: return super().__floordiv__(other) # pylint: disable=too-many-function-args - def __ifloordiv__(self, other: Self) -> Self: + def __ifloordiv__(self, other: npt.NDArray) -> Self: return super().__ifloordiv__(other) - def __rfloordiv__(self, other: Self) -> Self: + def __rfloordiv__(self, other: npt.NDArray) -> Self: return super().__rfloordiv__(other) def __neg__(self) -> Self: return super().__neg__() - def __mod__(self, other: Self) -> Self: + def __mod__(self, other: npt.NDArray) -> Self: return super().__mod__(other) - def __imod__(self, other: Self) -> Self: + def __imod__(self, other: npt.NDArray) -> Self: return super().__imod__(other) - def __rmod__(self, other: Self) -> Self: + def __rmod__(self, other: npt.NDArray) -> Self: return super().__rmod__(other) def __pow__(self, other: int | npt.NDArray) -> Self: @@ -520,10 +520,10 @@ def __ipow__(self, other: int | npt.NDArray) -> Self: # def __rpow__(self, other) -> Self: # return super().__rpow__(other) - def __matmul__(self, other: Self) -> Self: + def __matmul__(self, other: npt.NDArray) -> Self: return super().__matmul__(other) - def __rmatmul__(self, other: Self) -> Self: + def __rmatmul__(self, other: npt.NDArray) -> Self: return super().__rmatmul__(other) def __lshift__(self, other: int | npt.NDArray) -> Self: