Type generics and missing return types
This commit is contained in:
@@ -21,7 +21,7 @@ from rosbags.rosbag2 import Reader
|
||||
from rosbags.serde import deserialize_cdr
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Any
|
||||
from typing import Any, Generator
|
||||
|
||||
|
||||
class ReaderPy: # pylint: disable=too-few-public-methods
|
||||
@@ -35,7 +35,7 @@ class ReaderPy: # pylint: disable=too-few-public-methods
|
||||
self.reader.open(soptions, coptions)
|
||||
self.typemap = {x.name: x.type for x in self.reader.get_all_topics_and_types()}
|
||||
|
||||
def messages(self):
|
||||
def messages(self) -> Generator[tuple[str, str, int, bytes], None, None]:
|
||||
"""Expose rosbag2 like generator behavior."""
|
||||
while self.reader.has_next():
|
||||
topic, data, timestamp = self.reader.read_next()
|
||||
@@ -48,7 +48,7 @@ def deserialize_py(data: bytes, msgtype: str) -> Any:
|
||||
return deserialize_message(data, pytype)
|
||||
|
||||
|
||||
def compare_msg(lite: Any, native: Any):
|
||||
def compare_msg(lite: Any, native: Any) -> None:
|
||||
"""Compare rosbag2 (lite) vs rosbag2_py (native) message content.
|
||||
|
||||
Args:
|
||||
@@ -79,7 +79,7 @@ def compare_msg(lite: Any, native: Any):
|
||||
assert native_val == lite_val, f'{fieldname}: {native_val} != {lite_val}'
|
||||
|
||||
|
||||
def compare(path: Path):
|
||||
def compare(path: Path) -> None:
|
||||
"""Compare raw and deserialized messages."""
|
||||
with Reader(path) as reader:
|
||||
gens = (reader.messages(), ReaderPy(path).messages())
|
||||
@@ -100,7 +100,7 @@ def compare(path: Path):
|
||||
assert len(list(gens[1])) == 0
|
||||
|
||||
|
||||
def read_deser_rosbag2_py(path: Path):
|
||||
def read_deser_rosbag2_py(path: Path) -> None:
|
||||
"""Read testbag with rosbag2_py."""
|
||||
soptions = StorageOptions(str(path), 'sqlite3')
|
||||
coptions = ConverterOptions('', '')
|
||||
@@ -115,14 +115,14 @@ def read_deser_rosbag2_py(path: Path):
|
||||
deserialize_message(rawdata, pytype)
|
||||
|
||||
|
||||
def read_deser_rosbag2(path: Path):
|
||||
def read_deser_rosbag2(path: Path) -> None:
|
||||
"""Read testbag with rosbag2lite."""
|
||||
with Reader(path) as reader:
|
||||
for connection, _, data in reader.messages():
|
||||
deserialize_cdr(data, connection.msgtype)
|
||||
|
||||
|
||||
def main():
|
||||
def main() -> None:
|
||||
"""Benchmark rosbag2 against rosbag2_py."""
|
||||
path = Path(sys.argv[1])
|
||||
try:
|
||||
|
||||
@@ -25,7 +25,7 @@ rosgraph_msgs.msg.TopicStatistics = Mock()
|
||||
import rosbag.bag # type:ignore # noqa: E402 pylint: disable=wrong-import-position
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Any, List, Union
|
||||
from typing import Any, Generator, List, Union
|
||||
|
||||
from rosbag.bag import _Connection_Info
|
||||
|
||||
@@ -39,7 +39,7 @@ class Reader: # pylint: disable=too-few-public-methods
|
||||
self.reader.open(StorageOptions(path, 'sqlite3'), ConverterOptions('', ''))
|
||||
self.typemap = {x.name: x.type for x in self.reader.get_all_topics_and_types()}
|
||||
|
||||
def messages(self):
|
||||
def messages(self) -> Generator[tuple[str, int, bytes], None, None]:
|
||||
"""Expose rosbag2 like generator behavior."""
|
||||
while self.reader.has_next():
|
||||
topic, data, timestamp = self.reader.read_next()
|
||||
@@ -47,7 +47,7 @@ class Reader: # pylint: disable=too-few-public-methods
|
||||
yield topic, timestamp, deserialize_message(data, pytype)
|
||||
|
||||
|
||||
def fixup_ros1(conns: List[_Connection_Info]):
|
||||
def fixup_ros1(conns: List[_Connection_Info]) -> None:
|
||||
"""Monkeypatch ROS2 fieldnames onto ROS1 objects.
|
||||
|
||||
Args:
|
||||
@@ -69,16 +69,13 @@ def fixup_ros1(conns: List[_Connection_Info]):
|
||||
cls.p = property(lambda x: x.P, lambda x, y: setattr(x, 'P', y)) # noqa: B010
|
||||
|
||||
|
||||
def compare(ref: Any, msg: Any):
|
||||
def compare(ref: Any, msg: Any) -> None:
|
||||
"""Compare message to its reference.
|
||||
|
||||
Args:
|
||||
ref: Reference ROS1 message.
|
||||
msg: Converted ROS2 message.
|
||||
|
||||
Return:
|
||||
True if messages are identical.
|
||||
|
||||
"""
|
||||
if hasattr(msg, 'get_fields_and_field_types'):
|
||||
for name in msg.get_fields_and_field_types():
|
||||
@@ -107,7 +104,7 @@ def compare(ref: Any, msg: Any):
|
||||
assert ref == msg
|
||||
|
||||
|
||||
def main_bag1_bag1(path1: Path, path2: Path):
|
||||
def main_bag1_bag1(path1: Path, path2: Path) -> None:
|
||||
"""Compare rosbag1 to rosbag1 message by message.
|
||||
|
||||
Args:
|
||||
@@ -132,7 +129,7 @@ def main_bag1_bag1(path1: Path, path2: Path):
|
||||
print('Bags are identical.') # noqa: T001
|
||||
|
||||
|
||||
def main_bag1_bag2(path1: Path, path2: Path):
|
||||
def main_bag1_bag2(path1: Path, path2: Path) -> None:
|
||||
"""Compare rosbag1 to rosbag2 message by message.
|
||||
|
||||
Args:
|
||||
|
||||
Reference in New Issue
Block a user