From c707d1181480fb8673840099e2eca76c7f079110 Mon Sep 17 00:00:00 2001 From: Emerson Knapp Date: Mon, 22 Mar 2021 14:38:32 -0700 Subject: [PATCH] Use format strings for topic endpoint info printing Signed-off-by: Emerson Knapp --- rclpy/rclpy/duration.py | 2 +- rclpy/rclpy/topic_endpoint_info.py | 29 +++++++++++++++-------------- rclpy/src/rclpy/_rclpy_pybind11.cpp | 1 - 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/rclpy/rclpy/duration.py b/rclpy/rclpy/duration.py index a9a2e3991..50ef7f9cd 100644 --- a/rclpy/rclpy/duration.py +++ b/rclpy/rclpy/duration.py @@ -84,7 +84,7 @@ def from_msg(cls, msg): @classmethod def Infinite(cls): - return cls(nanoseconds=_rclpy.rclpy_RMW_DURATION_INFINITE) + return cls(nanoseconds=_rclpy.RMW_DURATION_INFINITE) def get_c_duration(self): return self._duration_handle diff --git a/rclpy/rclpy/topic_endpoint_info.py b/rclpy/rclpy/topic_endpoint_info.py index 408f43965..7569a926d 100644 --- a/rclpy/rclpy/topic_endpoint_info.py +++ b/rclpy/rclpy/topic_endpoint_info.py @@ -158,17 +158,18 @@ def __eq__(self, other): for slot in self.__slots__) def __str__(self): - result = 'Node name: %s\n' % self.node_name - result += 'Node namespace: %s\n' % self.node_namespace - result += 'Topic type: %s\n' % self.topic_type - result += 'Endpoint type: %s\n' % self.endpoint_type.name - result += 'GID: %s\n' % '.'.join(format(x, '02x') for x in self.endpoint_gid) - result += 'QoS profile:\n' - result += ' Reliability: %s\n' % self.qos_profile.reliability.name - result += ' Durability: %s\n' % self.qos_profile.durability.name - result += ' Lifespan: %s\n' % str(self.qos_profile.lifespan) - result += ' Deadline: %s\n' % str(self.qos_profile.deadline) - result += ' Liveliness: %s\n' % self.qos_profile.liveliness.name - result += ' Liveliness lease duration: %s' % \ - str(self.qos_profile.liveliness_lease_duration) - return result + gid = '.'.join(format(x, '02x') for x in self.endpoint_gid) + return '\n'.join([ + f'Node name: {self.node_name}', + f'Node namespace: {self.node_namespace}', + f'Topic type: {self.topic_type}', + f'Endpoint type: {self.endpoint_type.name}', + f'GID: {gid}', + 'QoS profile:', + f' Reliability: {self.qos_profile.reliability.name}', + f' Durability: {self.qos_profile.durability.name}', + f' Lifespan: {self.qos_profile.lifespan}', + f' Deadline: {self.qos_profile.deadline}', + f' Liveliness: {self.qos_profile.liveliness.name}', + f' Liveliness lease duration: {self.qos_profile.liveliness_lease_duration}', + ]) diff --git a/rclpy/src/rclpy/_rclpy_pybind11.cpp b/rclpy/src/rclpy/_rclpy_pybind11.cpp index af6fa6aea..01df8143c 100644 --- a/rclpy/src/rclpy/_rclpy_pybind11.cpp +++ b/rclpy/src/rclpy/_rclpy_pybind11.cpp @@ -86,7 +86,6 @@ PYBIND11_MODULE(_rclpy_pybind11, m) { .def_readonly("compatibility", &rclpy::QoSCheckCompatibleResult::compatibility) .def_readonly("reason", &rclpy::QoSCheckCompatibleResult::reason); - py::register_exception(m, "RCUtilsError", PyExc_RuntimeError); py::register_exception(m, "RMWError", PyExc_RuntimeError); auto rclerror = py::register_exception(m, "RCLError", PyExc_RuntimeError);