Skip to content

Commit e904c2e

Browse files
Edited the template to provide better docstring for message definition
issue: #196 Transcribed the original message comments in the python docstring
1 parent f1451cf commit e904c2e

File tree

2 files changed

+50
-5
lines changed

2 files changed

+50
-5
lines changed

rosidl_generator_py/resource/_msg.py.em

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,18 +189,63 @@ for member in message.structure.members:
189189

190190

191191
class @(message.structure.namespaced_type.name)(metaclass=Metaclass_@(message.structure.namespaced_type.name)):
192-
@[if not message.constants]@
193-
"""Message class '@(message.structure.namespaced_type.name)'."""
194-
@[else]@
195192
"""
196193
Message class '@(message.structure.namespaced_type.name)'.
194+
@[if message.constants]@
195+
@("\n" + "\n ".join(message.structure.get_comment_lines()) + "\n")@
196+
@[if message.constants]@
197197
198198
Constants:
199199
@[ for constant_name in [c.name for c in message.constants]]@
200200
@(constant_name)
201201
@[ end for]@
202-
"""
203202
@[end if]@
203+
@[if message.structure.members]@
204+
205+
Fields:
206+
@[for member in message.structure.members]@
207+
@[ if len(message.structure.members) == 1 and member.name == EMPTY_STRUCTURE_REQUIRED_MEMBER_NAME]@
208+
@[ continue]@
209+
@[ end if]@
210+
@{
211+
type_ = member.type
212+
if isinstance(type_, AbstractNestedType):
213+
type_ = type_.value_type
214+
}@
215+
@(member.name) (@
216+
@# the prefix for nested types
217+
@[ if isinstance(member.type, AbstractSequence)]@
218+
sequence<@
219+
@[ end if]@
220+
@# the typename of the non-nested type or the nested basetype
221+
@[ if isinstance(type_, BasicType)]@
222+
@(type_.typename)@
223+
@[ elif isinstance(type_, AbstractGenericString)]@
224+
@
225+
@[ if isinstance(type_, AbstractWString)]@
226+
w@
227+
@[ end if]@
228+
string@
229+
@[ if type_.has_maximum_size()]@
230+
<@(type_.maximum_size)>@
231+
@[ end if]@
232+
@[ elif isinstance(type_, NamespacedType)]@
233+
@('/'.join([type_.namespaces[0], type_.name]))@
234+
@[ end if]@
235+
@# the suffix for nested types
236+
@[ if isinstance(member.type, AbstractSequence)]@
237+
@[ if isinstance(member.type, BoundedSequence)]@
238+
, @(member.type.maximum_size)@
239+
@[ end if]@
240+
>@
241+
@[ elif isinstance(member.type, Array)]@
242+
[@(member.type.size)]@
243+
@[ end if]@
244+
)@(" ".join([':'] + member.get_comment_lines()).strip(' '))@
245+
246+
@[end for]@
247+
@[end if]@
248+
"""
204249

205250
__slots__ = [
206251
@[for member in message.structure.members]@

rosidl_generator_py/test/test_interfaces.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def test_arrays_of_bounded_strings():
262262
def test_constructor():
263263
msg = Strings(string_value='foo', check_fields=True)
264264

265-
assert'foo' == msg.string_value
265+
assert 'foo' == msg.string_value
266266

267267
with pytest.raises(AssertionError):
268268
Strings(unknown_field='test', check_fields=True)

0 commit comments

Comments
 (0)