diff --git a/rosidl_generator_py/resource/_msg.py.em b/rosidl_generator_py/resource/_msg.py.em index 8c21e552..92357082 100644 --- a/rosidl_generator_py/resource/_msg.py.em +++ b/rosidl_generator_py/resource/_msg.py.em @@ -189,18 +189,63 @@ for member in message.structure.members: class @(message.structure.namespaced_type.name)(metaclass=Metaclass_@(message.structure.namespaced_type.name)): -@[if not message.constants]@ - """Message class '@(message.structure.namespaced_type.name)'.""" -@[else]@ """ Message class '@(message.structure.namespaced_type.name)'. +@[if message.constants]@ + @("\n" + "\n ".join(message.structure.get_comment_lines()) + "\n")@ +@[if message.constants]@ Constants: @[ for constant_name in [c.name for c in message.constants]]@ @(constant_name) @[ end for]@ - """ @[end if]@ +@[if message.structure.members]@ + + Fields: +@[for member in message.structure.members]@ +@[ if len(message.structure.members) == 1 and member.name == EMPTY_STRUCTURE_REQUIRED_MEMBER_NAME]@ +@[ continue]@ +@[ end if]@ +@{ +type_ = member.type +if isinstance(type_, AbstractNestedType): + type_ = type_.value_type +}@ + @(member.name) (@ +@# the prefix for nested types +@[ if isinstance(member.type, AbstractSequence)]@ +sequence<@ +@[ end if]@ +@# the typename of the non-nested type or the nested basetype +@[ if isinstance(type_, BasicType)]@ +@(type_.typename)@ +@[ elif isinstance(type_, AbstractGenericString)]@ +@ +@[ if isinstance(type_, AbstractWString)]@ +w@ +@[ end if]@ +string@ +@[ if type_.has_maximum_size()]@ +<@(type_.maximum_size)>@ +@[ end if]@ +@[ elif isinstance(type_, NamespacedType)]@ +@('/'.join([type_.namespaces[0], type_.name]))@ +@[ end if]@ +@# the suffix for nested types +@[ if isinstance(member.type, AbstractSequence)]@ +@[ if isinstance(member.type, BoundedSequence)]@ +, @(member.type.maximum_size)@ +@[ end if]@ +>@ +@[ elif isinstance(member.type, Array)]@ +[@(member.type.size)]@ +@[ end if]@ +)@(" ".join([':'] + member.get_comment_lines()).strip(' '))@ + +@[end for]@ +@[end if]@ + """ __slots__ = [ @[for member in message.structure.members]@ diff --git a/rosidl_generator_py/test/test_interfaces.py b/rosidl_generator_py/test/test_interfaces.py index e0874bcd..100beed9 100644 --- a/rosidl_generator_py/test/test_interfaces.py +++ b/rosidl_generator_py/test/test_interfaces.py @@ -262,7 +262,7 @@ def test_arrays_of_bounded_strings(): def test_constructor(): msg = Strings(string_value='foo', check_fields=True) - assert'foo' == msg.string_value + assert 'foo' == msg.string_value with pytest.raises(AssertionError): Strings(unknown_field='test', check_fields=True)