From 8f5b6f58d12ef0f0edd5f9ebcf44c71dc2a5ff47 Mon Sep 17 00:00:00 2001 From: Magnus Wolffelt Date: Mon, 16 Aug 2021 10:03:40 +0200 Subject: [PATCH] Add rmul to distance and speeds, so that reversed operands work --- game/utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/game/utils.py b/game/utils.py index 119a741a..fbb28d0e 100644 --- a/game/utils.py +++ b/game/utils.py @@ -62,6 +62,8 @@ class Distance: def __mul__(self, other: Union[float, int]) -> Distance: return meters(self.meters * other) + __rmul__ = __mul__ + def __truediv__(self, other: Union[float, int]) -> Distance: return meters(self.meters / other) @@ -147,6 +149,8 @@ class Speed: def __mul__(self, other: Union[float, int]) -> Speed: return kph(self.kph * other) + __rmul__ = __mul__ + def __truediv__(self, other: Union[float, int]) -> Speed: return kph(self.kph / other)