-
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
Ensure the contents of the field are an array. #63
Conversation
It turns out that while all AbstractSequences are *defined* to be arrays, we allow users to assign other sequences (like lists) to those fields. Make sure that the field starts with 'array(' before trying to strip it off. Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
# It is possible that the user assigned a non-array type to | ||
# the AbstractSequence field, so only remove 'array(' if it | ||
# is in the string. | ||
if fieldstr.startswith('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.
Please move the check into the else
block since there is no reason for it on the if
block.
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.
Done in 810ac05
When the user assigns a list to an array field I would expect the setter function to ensure that the actually stored value is an rosidl_python/rosidl_generator_py/resource/_msg.py.em Lines 520 to 524 in f78c207
So I think before making this change we need to investigate why that is not the case (and maybe address that instead). |
Yeah, that occurred to me too. I put this up so we could get it in quickly, but since this isn't a rush for release now we should probably investigate that. |
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
I see where the discrepancy is. The problem shows up for types that are not in the SPECIAL_NESTED_BASIC_TYPES. If the message has a Sequence of booleans, for instance, there is no way to directly map them to an array. So the generated setter only checks if the new value is a valid Sequence, and does a direct assignment. While we could potentially think about coercion to an I think the fallout from this is that we do need to handle regular Sequences along with |
Based on your argument I don't think the current patch is right. I would rather change the condition |
The problem with that is that SPECIAL_NESTED_BASIC_TYPES comes from https://github.com/ros2/rosidl_python/blob/master/rosidl_generator_py/rosidl_generator_py/generate_py_impl.py#L37 , and we don't currently import rosidl_generator_py at runtime for the generated messages. Our options seem to be:
I'm not really hugely in favor of importing |
How about 4. use |
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
Done in 0e8e345. New CI: |
# a type that we store in an array, strip off the 'array' portion. | ||
if isinstance(t, rosidl_parser.definition.AbstractSequence) and \ | ||
isinstance(t.value_type, rosidl_parser.definition.BasicType) and \ | ||
t.value_type.typename in @([*SPECIAL_NESTED_BASIC_TYPES]): |
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.
Nitpick: the multi line condition isn't distinguishable from the indented block. Please use the following style instead:
if (
... and
...
):
...
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.
Done in f7b18f6
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
CI is green (Windows test failures are unrelated), so I'm going to merge. |
* Ensure the contents of the field are an array. It turns out that while all AbstractSequences are *defined* to be arrays, we allow users to assign other sequences (like lists) to those fields. Make sure that the field starts with 'array(' before trying to strip it off. Signed-off-by: Chris Lalancette <clalancette@openrobotics.org> * Changes from review. Signed-off-by: Chris Lalancette <clalancette@openrobotics.org> * Look at the type.value_type to determine whether it is an array. Signed-off-by: Chris Lalancette <clalancette@openrobotics.org> * Review feedback. Signed-off-by: Chris Lalancette <clalancette@openrobotics.org> * Fix flake8 warnings. Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
* Ensure the contents of the field are an array. It turns out that while all AbstractSequences are *defined* to be arrays, we allow users to assign other sequences (like lists) to those fields. Make sure that the field starts with 'array(' before trying to strip it off. Signed-off-by: Chris Lalancette <clalancette@openrobotics.org> * Changes from review. Signed-off-by: Chris Lalancette <clalancette@openrobotics.org> * Look at the type.value_type to determine whether it is an array. Signed-off-by: Chris Lalancette <clalancette@openrobotics.org> * Review feedback. Signed-off-by: Chris Lalancette <clalancette@openrobotics.org> * Fix flake8 warnings. Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
It turns out that while all AbstractSequences are defined
to be arrays, we allow users to assign other sequences (like
lists) to those fields. Make sure that the field starts with
'array(' before trying to strip it off.
Signed-off-by: Chris Lalancette clalancette@openrobotics.org
This should fix ros2/build_farmer#212