Skip to content

Commit b44074c

Browse files
authored
Merge pull request #233 from UZ9/master
Fix TypeError resulting from lack of __rmul__
2 parents c1462ba + 425a5de commit b44074c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

vpython/cyvector.pyx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ cdef class vector(object):
8585
return vector(self * other._x, self * other._y, self * other._z)
8686
return NotImplemented
8787

88+
def __rmul__(self, other): # required to prevent y * x error
89+
if isinstance(other, (float, int)):
90+
return vector(self._x * other, self._y * other, self._z * other)
91+
92+
return NotImplemented
93+
8894
def __eq__(self,other):
8995
if type(self) is vector and type(other) is vector:
9096
return self.equals(other)

0 commit comments

Comments
 (0)