Skip to content
This repository was archived by the owner on Mar 31, 2020. It is now read-only.

Commit 4b03afa

Browse files
committed
Fixed hard coded classes
1 parent 29efd42 commit 4b03afa

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/animate.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ class Coord(NamedTuple):
4040
Operand = TypeVar('Operand', 'Coord', float)
4141

4242
def __apply(self, op: Callable, other: Coord.Operand) -> Coord:
43-
if not isinstance(other, Coord):
44-
other = Coord(other, other)
43+
if not isinstance(other, self.__class__):
44+
other = self.__class__(other, other)
4545

4646
x = op(self.x, other.x)
4747
y = op(self.y, other.y)
48-
return Coord(x, y)
48+
return self.__class__(x, y)
4949

5050
def midpoint(self, other: Coord) -> Coord:
5151
"""
@@ -103,7 +103,10 @@ def __mul__(self, other: int) -> Coord:
103103
return self.value * other
104104

105105
def __add__(self, other: Direction) -> Coord:
106-
return self.value + other.value
106+
if isinstance(other, self.__class__):
107+
return self.value + other.value
108+
else:
109+
return self.value + other
107110

108111

109112
class Animater(tk.Canvas):

0 commit comments

Comments
 (0)