-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the setting of array variables. #59
Conversation
If the type of the field is array.array, then a simple x = array.array(mylist) doesn't work; the typecode *must* be specified. Special-case arrays here so that we do: x = array.array(typecode, list) Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
field_typecode = getattr(msg, field_name).typecode | ||
value = field_type(field_typecode, field_value) | ||
else: | ||
value = field_type(field_value) | ||
except TypeError: | ||
value = field_type() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we ever hit a TypeError
when the field_type
is array.array
, then we'll throw a different exception here since you can't instantiate an array.array
without a typecode. However, I couldn't see how that would happen, so I didn't make any changes here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please apply the same conditional logic in the exception case to construct and empty array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in a29f80f
Can you please check if sequences (with a dynamic size) are also affect and need a similar fix. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works locally, LGTM!
@@ -34,7 +36,11 @@ def set_message_fields(msg: Any, values: Dict[str, str]) -> None: | |||
for field_name, field_value in values.items(): | |||
field_type = type(getattr(msg, field_name)) | |||
try: | |||
value = field_type(field_value) | |||
if field_type == array.array: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@clalancette nit:
if field_type == array.array: | |
if field_type is array.array: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in a29f80f
Good call, will check on that next. |
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
As far as I can tell, the sequence stuff works (at least, basically). I ran:
Which seemed to work fine. In retrospect, that's because Sequences (lists and tuples, at least) can be instantiated with just There is also a different bug in there, in that sending the wrong type for the data gives an opaque error message, but I'll ticket that separately. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (haven't tried it though have tried it and it resolves the referenced ticket)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't tried it, but looks good.
#61 is the follow-up. It's in the same area, but I'm running out of time today. Since it's a cosmetic issue, I think we can punt to after Dashing. CI up to rosidl_runtime_py: |
* Fix the setting of array variables. If the type of the field is array.array, then a simple x = array.array(mylist) doesn't work; the typecode *must* be specified. Special-case arrays here so that we do: x = array.array(typecode, list) Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
If the type of the field is array.array, then a simple
x = array.array(mylist)
doesn't work; the typecode must be specified. Special-case
arrays here so that we do:
x = array.array(typecode, list)
Signed-off-by: Chris Lalancette clalancette@openrobotics.org
This should fix ros2/ros2cli#270