Skip to content

Commit

Permalink
Fix failure on Py3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBB committed Feb 12, 2024
1 parent 970268e commit 2667610
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions splipy/splineobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
from operator import attrgetter, methodcaller
from itertools import product
from bisect import bisect_left
from types import NotImplementedType
from typing import Sequence, Any, Optional, SupportsIndex, Union, SupportsFloat, Protocol, cast, TypeVar, Generic, Iterator, Literal, overload, Callable, MutableSequence, ClassVar
from typing_extensions import Self, Unpack
from typing_extensions import Self, Unpack, TypeAlias
from numpy.typing import ArrayLike

from .basis import BSplineBasis
Expand Down Expand Up @@ -1499,19 +1498,22 @@ def shape(self) -> tuple[int, ...]:
"""The dimensions of the control point array."""
return self.controlpoints.shape[:-1]

def __iadd__(self, x: Any) -> Union[Self, NotImplementedType]:
# TODO: Py310 from types import NotImplementedType
# Then change all the return types to Self | NotImplementedType

def __iadd__(self, x: Any) -> Self:
if isinstance(x, (Sequence, np.ndarray)):
self.translate(x)
return self
return NotImplemented

def __isub__(self, x: Any) -> Union[Self, NotImplementedType]:
def __isub__(self, x: Any) -> Self:
if isinstance(x, (Sequence, np.ndarray)):
self.translate(-np.array(x, dtype=float)) # can't do -x if x is a list, so we rewrap it here
return self
return NotImplemented

def __imul__(self, x: Any) -> Union[Self, NotImplementedType]:
def __imul__(self, x: Any) -> Self:
if isinstance(x, (Sequence, np.ndarray)):
self.scale(*x)
return self
Expand All @@ -1523,7 +1525,7 @@ def __imul__(self, x: Any) -> Union[Self, NotImplementedType]:
return self
return NotImplemented

def __itruediv__(self, x: Any) -> Union[Self, NotImplementedType]:
def __itruediv__(self, x: Any) -> Self:
if isinstance(x, (Sequence, np.ndarray)):
y = 1 / np.ndarray(x, dtype=float)
self.scale(*y)
Expand All @@ -1538,22 +1540,22 @@ def __itruediv__(self, x: Any) -> Union[Self, NotImplementedType]:

__ifloordiv__ = __itruediv__ # integer division (should not distinguish)

def __add__(self, x: Any) -> Union[Self, NotImplementedType]:
def __add__(self, x: Any) -> Self:
return self.clone().__iadd__(x)

def __radd__(self, x: Any) -> Union[Self, NotImplementedType]:
def __radd__(self, x: Any) -> Self:
return self.__add__(x)

def __sub__(self, x: Any) -> Union[Self, NotImplementedType]:
def __sub__(self, x: Any) -> Self:
return self.clone().__isub__(x)

def __mul__(self, x: Any) -> Union[Self, NotImplementedType]:
def __mul__(self, x: Any) -> Self:
return self.clone().__imul__(x)

def __rmul__(self, x: Any) -> Union[Self, NotImplementedType]:
def __rmul__(self, x: Any) -> Self:
return self.__mul__(x)

def __div__(self, x: Any) -> Union[Self, NotImplementedType]:
def __div__(self, x: Any) -> Self:
return self.clone().__itruediv__(x)

def flip_and_move_plane_geometry(self, center: Scalars = (0,0,0), normal: Scalars = (0,0,1)) -> Self:
Expand Down

0 comments on commit 2667610

Please sign in to comment.