Fix up all the runtime errors caused by the previous refactoring
This commit is contained in:
parent
f1b95a697e
commit
a54828c7fb
4 changed files with 40 additions and 20 deletions
|
|
@ -11,15 +11,23 @@ class Point:
|
|||
self.y = y
|
||||
|
||||
@overload
|
||||
def __add__(self, other: Vector) -> Point:
|
||||
def __add__(self, other: 'Vector') -> 'Point':
|
||||
...
|
||||
|
||||
@overload
|
||||
def __add__(self, other) -> Point:
|
||||
def __add__(self, other) -> 'Point':
|
||||
if not isinstance(other, Vector):
|
||||
raise TypeError('Only Vector can be added to a Point')
|
||||
return Point(self.x + other.dx, self.y + other.dy)
|
||||
|
||||
@overload
|
||||
def __eq__(self, other: 'Point') -> bool:
|
||||
...
|
||||
|
||||
def __eq__(self, other):
|
||||
if not isinstance(other, Point):
|
||||
raise TypeError('Points can only be compared to other Points')
|
||||
return self.x == other.x and self.y == other.y
|
||||
|
||||
def __str__(self):
|
||||
return f'(x:{self.x}, y:{self.y})'
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue