Skip to content

Commit 5f905b2

Browse files
committed
mypy
1 parent e6008aa commit 5f905b2

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

mqtt_ros_bridge/encodings.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from typing import Protocol, Type, TypeVar, NoReturn, TypeAlias
1+
from typing import Protocol, Type, TypeVar, TypeAlias
22

33
import json
44
from rclpy.type_support import check_is_valid_msg_type
55

66

7-
NestedDictionary: TypeAlias = dict[str, 'NestedDictionary'] | dict[str, str] | dict[str, NoReturn]
7+
NestedDictionary: TypeAlias = dict[str, 'NestedDictionary'] | dict[str, str]
88

99

1010
class MsgLike(Protocol):
@@ -27,7 +27,7 @@ def human_readable_encoding(msg: MsgLike) -> bytes:
2727

2828

2929
def human_readable_encoding_recursive(msg: MsgLike) -> NestedDictionary:
30-
msg_dict: NestedDictionary = {}
30+
msg_dict = {}
3131
for field, field_types in (msg.get_fields_and_field_types()).items():
3232
value = getattr(msg, field)
3333

@@ -53,13 +53,15 @@ def human_readable_decoding(byte_msg: bytes, msg_type: Type[MsgLikeT]) -> MsgLik
5353
def human_readable_decoding_recursive(msg_dict: NestedDictionary,
5454
msg_type: Type[MsgLikeT]) -> MsgLikeT:
5555
msg = msg_type()
56-
56+
set_value: object
5757
for field, value in msg_dict.items():
5858
if isinstance(getattr(msg, field), bytes):
5959
if isinstance(value, str):
60-
value = value.encode()
60+
set_value = value.encode()
6161
elif isinstance(value, dict):
62-
value = human_readable_decoding_recursive(value, type(getattr(msg, field)))
62+
set_value = human_readable_decoding_recursive(value, type(getattr(msg, field)))
63+
else:
64+
set_value = value
6365

64-
setattr(msg, field, value)
66+
setattr(msg, field, set_value)
6567
return msg

0 commit comments

Comments
 (0)