From 294955467fdca06dfc6beeadaf7047aab7996e9b Mon Sep 17 00:00:00 2001 From: Michael Carlstrom Date: Thu, 8 Aug 2024 16:32:15 -0400 Subject: [PATCH] Fix time subtraction (#1312) Signed-off-by: Michael Carlstrom Co-authored-by: Shane Loretz --- rclpy/rclpy/time.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/rclpy/rclpy/time.py b/rclpy/rclpy/time.py index 031a04380..57693a00b 100644 --- a/rclpy/rclpy/time.py +++ b/rclpy/rclpy/time.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from typing import Protocol, Tuple, Union +from typing import overload, Protocol, Tuple, Union import builtin_interfaces.msg @@ -95,6 +95,12 @@ def __add__(self, other: Duration) -> 'Time': def __radd__(self, other: Duration) -> 'Time': return self.__add__(other) + @overload + def __sub__(self, other: 'Time') -> Duration: ... + + @overload + def __sub__(self, other: Duration) -> 'Time': ... + def __sub__(self, other: Union['Time', Duration]) -> Union['Time', Duration]: if isinstance(other, Time): if self.clock_type != other.clock_type: