diff --git a/rclpy/rclpy/duration.py b/rclpy/rclpy/duration.py index 50ef7f9cd..4fde06f38 100644 --- a/rclpy/rclpy/duration.py +++ b/rclpy/rclpy/duration.py @@ -35,7 +35,7 @@ def __repr__(self): return 'Duration(nanoseconds={0})'.format(self.nanoseconds) def __str__(self): - if self == Duration.Infinite(): + if self == Infinite: return 'Infinite' return f'{self.nanoseconds} nanoseconds' @@ -82,9 +82,9 @@ def from_msg(cls, msg): raise TypeError('Must pass a builtin_interfaces.msg.Duration object') return cls(seconds=msg.sec, nanoseconds=msg.nanosec) - @classmethod - def Infinite(cls): - return cls(nanoseconds=_rclpy.RMW_DURATION_INFINITE) - def get_c_duration(self): return self._duration_handle + + +# Constant representing an infinite amount of time. +Infinite = Duration(nanoseconds=_rclpy.RMW_DURATION_INFINITE) diff --git a/rclpy/test/test_time.py b/rclpy/test/test_time.py index bf69b4936..c89aa0a4b 100644 --- a/rclpy/test/test_time.py +++ b/rclpy/test/test_time.py @@ -16,6 +16,7 @@ from rclpy.clock import ClockType from rclpy.duration import Duration +from rclpy.duration import Infinite from rclpy.time import Time from test_msgs.msg import Builtins @@ -230,5 +231,5 @@ def test_seconds_nanoseconds(self): assert (0, 0) == Time().seconds_nanoseconds() def test_infinite_duration(self): - duration = Duration.Infinite() + duration = Infinite assert str(duration) == 'Infinite'