Skip to content

Commit d7872fa

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 d7872fa

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

rosidl_generator_py/resource/_msg.py.em

+54-4
Original file line numberDiff line numberDiff line change
@@ -189,18 +189,68 @@ 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 len(message.structure.get_comment_lines()) > 0]@
195+
196+
@[ for comment in message.structure.get_comment_lines()]@
197+
@((" " + comment).rstrip(' ') + "\n")@
198+
@[ end for]@
199+
@[end if]@
200+
201+
@[if message.constants]@
197202
198203
Constants:
199204
@[ for constant_name in [c.name for c in message.constants]]@
200205
@(constant_name)
201206
@[ end for]@
202-
"""
203207
@[end if]@
208+
@[if message.structure.members]@
209+
210+
Fields:
211+
@[for member in message.structure.members]@
212+
@[ if len(message.structure.members) == 1 and member.name == EMPTY_STRUCTURE_REQUIRED_MEMBER_NAME]@
213+
@[ continue]@
214+
@[ end if]@
215+
@{
216+
type_ = member.type
217+
if isinstance(type_, AbstractNestedType):
218+
type_ = type_.value_type
219+
}@
220+
@(member.name) (@
221+
@# the prefix for nested types
222+
@[ if isinstance(member.type, AbstractSequence)]@
223+
sequence<@
224+
@[ end if]@
225+
@# the typename of the non-nested type or the nested basetype
226+
@[ if isinstance(type_, BasicType)]@
227+
@(type_.typename)@
228+
@[ elif isinstance(type_, AbstractGenericString)]@
229+
@
230+
@[ if isinstance(type_, AbstractWString)]@
231+
w@
232+
@[ end if]@
233+
string@
234+
@[ if type_.has_maximum_size()]@
235+
<@(type_.maximum_size)>@
236+
@[ end if]@
237+
@[ elif isinstance(type_, NamespacedType)]@
238+
@('/'.join([type_.namespaces[0], type_.name]))@
239+
@[ end if]@
240+
@# the suffix for nested types
241+
@[ if isinstance(member.type, AbstractSequence)]@
242+
@[ if isinstance(member.type, BoundedSequence)]@
243+
, @(member.type.maximum_size)@
244+
@[ end if]@
245+
>@
246+
@[ elif isinstance(member.type, Array)]@
247+
[@(member.type.size)]@
248+
@[ end if]@
249+
)@(" ".join([':'] + member.get_comment_lines()).strip(' '))@
250+
251+
@[end for]@
252+
@[end if]@
253+
"""
204254

205255
__slots__ = [
206256
@[for member in message.structure.members]@

rosidl_generator_py/test/test_interfaces.py

+1-1
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)