From ee3c628314fcb0d4b639528bce712656bfe8dee7 Mon Sep 17 00:00:00 2001 From: Michael Grupp Date: Mon, 14 Oct 2024 16:06:49 +0200 Subject: [PATCH] mypy: add __lt__ to ROS1/2 protocol in tf_cache (#695) mypy now checks overloads more strictly. Required to make the `timestamps.sort()` call using both protocols type-checkable. --- evo/tools/tf_cache.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/evo/tools/tf_cache.py b/evo/tools/tf_cache.py index 2a0cce6..8a39131 100644 --- a/evo/tools/tf_cache.py +++ b/evo/tools/tf_cache.py @@ -24,8 +24,14 @@ import math import warnings from collections import defaultdict -from typing import (DefaultDict, List, Optional, Protocol, Union, - runtime_checkable) +from typing import ( + DefaultDict, + List, + Optional, + Protocol, + Union, + runtime_checkable, +) import numpy as np import tf2_py @@ -60,6 +66,9 @@ def to_sec(self) -> float: Gets scalar time, in seconds. """ + def __lt__(self, other) -> bool: + """ less-than comparator, required for sorting """ + @runtime_checkable class Ros2TimeLike(Protocol): # pylint: disable=too-few-public-methods @@ -72,6 +81,9 @@ def nanoseconds(self) -> int: Gets underlying scalar timestamp, in nanoseconds. """ + def __lt__(self, other) -> bool: + """ less-than comparator, required for sorting """ + @runtime_checkable class Ros2StampLike(Protocol): # pylint: disable=too-few-public-methods