Skip to content

Commit

Permalink
Changes the use of __slots__ for the field and field type getter (#87)
Browse files Browse the repository at this point in the history
* Changes the use of __slots__ for the field and field type getter

Signed-off-by: Voldivh <eloyabmfcv@gmail.com>
  • Loading branch information
Voldivh committed Apr 4, 2023
1 parent 726c375 commit 7693fbb
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/rqt_plot/plot_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,12 @@ def get_plot_fields(node, topic_name):
no_field_error_msg = base_error_msg + f"'{name}' is not a field of '{topic_type_str}'"

try:
slot_index = current_message_class.__slots__.index(f'_{name}')
# This can only be done because the dict is order preserving and all the field name and values
# are stored in the same order.
field_name_index = list(current_message_class.get_fields_and_field_types().keys()).index(f'_{name}')
except ValueError:
return [], no_field_error_msg
current_type = current_message_class.SLOT_TYPES[slot_index]
current_type = current_message_class.SLOT_TYPES[field_name_index]
is_array_or_sequence = isinstance(current_type, AbstractNestedType)

if is_array_or_sequence:
Expand Down Expand Up @@ -159,7 +161,7 @@ def get_plot_fields(node, topic_name):
plottable_fields = []
current_message_class = import_message_from_namespaced_type(current_type)
for n_field, n_current_type in zip(
current_message_class.__slots__, current_message_class.SLOT_TYPES
current_message_class.get_fields_and_field_types().keys(), current_message_class.SLOT_TYPES
):
if isinstance(n_current_type, BasicType):
plottable_fields.append(n_field[1:])
Expand Down

0 comments on commit 7693fbb

Please sign in to comment.