1
- from typing import Protocol , Type , TypeVar , NoReturn , TypeAlias
1
+ from typing import Protocol , Type , TypeVar , TypeAlias
2
2
3
3
import json
4
4
from rclpy .type_support import check_is_valid_msg_type
5
5
6
6
7
- NestedDictionary : TypeAlias = dict [str , 'NestedDictionary' ] | dict [str , str ] | dict [ str , NoReturn ]
7
+ NestedDictionary : TypeAlias = dict [str , 'NestedDictionary' ] | dict [str , str ]
8
8
9
9
10
10
class MsgLike (Protocol ):
@@ -27,7 +27,7 @@ def human_readable_encoding(msg: MsgLike) -> bytes:
27
27
28
28
29
29
def human_readable_encoding_recursive (msg : MsgLike ) -> NestedDictionary :
30
- msg_dict : NestedDictionary = {}
30
+ msg_dict = {}
31
31
for field , field_types in (msg .get_fields_and_field_types ()).items ():
32
32
value = getattr (msg , field )
33
33
@@ -53,13 +53,15 @@ def human_readable_decoding(byte_msg: bytes, msg_type: Type[MsgLikeT]) -> MsgLik
53
53
def human_readable_decoding_recursive (msg_dict : NestedDictionary ,
54
54
msg_type : Type [MsgLikeT ]) -> MsgLikeT :
55
55
msg = msg_type ()
56
-
56
+ set_value : object
57
57
for field , value in msg_dict .items ():
58
58
if isinstance (getattr (msg , field ), bytes ):
59
59
if isinstance (value , str ):
60
- value = value .encode ()
60
+ set_value = value .encode ()
61
61
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
63
65
64
- setattr (msg , field , value )
66
+ setattr (msg , field , set_value )
65
67
return msg
0 commit comments