Skip to content

Commit

Permalink
mypy: add __lt__ to ROS1/2 protocol in tf_cache (#695)
Browse files Browse the repository at this point in the history
mypy now checks overloads more strictly. Required to make the
`timestamps.sort()` call using both protocols type-checkable.
  • Loading branch information
MichaelGrupp authored Oct 14, 2024
1 parent 97f2ca4 commit ee3c628
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions evo/tools/tf_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ee3c628

Please sign in to comment.