Skip to content
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

Edited the template to provide better docstring for message definition #197

Open
wants to merge 1 commit into
base: rolling
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 54 additions & 4 deletions rosidl_generator_py/resource/_msg.py.em
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,68 @@ 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 len(message.structure.get_comment_lines()) > 0]@

@[ for comment in message.structure.get_comment_lines()]@
@((" " + comment).rstrip(' ') + "\n")@
@[ end for]@
@[end if]@

@[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]@
Expand Down
2 changes: 1 addition & 1 deletion rosidl_generator_py/test/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down