Format field comments also as docstrings (#304)
Closes #303 * Format field comments also as docstrings To make it clear that they refer to the item above. * Fix placement of enum item docstrings * Add line breaks after class attribute or enum item docstrings
This commit is contained in:
parent
d991040ff6
commit
9b5594adbe
@ -142,17 +142,13 @@ def get_comment(
|
||||
sci_loc.leading_comments.strip().replace("\n", ""), width=79 - indent
|
||||
)
|
||||
|
||||
if path[-2] == 2 and path[-4] != 6:
|
||||
# This is a field
|
||||
return f"{pad}# " + f"\n{pad}# ".join(lines)
|
||||
# This is a field, message, enum, service, or method
|
||||
if len(lines) == 1 and len(lines[0]) < 79 - indent - 6:
|
||||
lines[0] = lines[0].strip('"')
|
||||
return f'{pad}"""{lines[0]}"""'
|
||||
else:
|
||||
# This is a message, enum, service, or method
|
||||
if len(lines) == 1 and len(lines[0]) < 79 - indent - 6:
|
||||
lines[0] = lines[0].strip('"')
|
||||
return f'{pad}"""{lines[0]}"""'
|
||||
else:
|
||||
joined = f"\n{pad}".join(lines)
|
||||
return f'{pad}"""\n{pad}{joined}\n{pad}"""'
|
||||
joined = f"\n{pad}".join(lines)
|
||||
return f'{pad}"""\n{pad}{joined}\n{pad}"""'
|
||||
|
||||
return ""
|
||||
|
||||
|
@ -28,10 +28,11 @@ class {{ enum.py_name }}(betterproto.Enum):
|
||||
|
||||
{% endif %}
|
||||
{% for entry in enum.entries %}
|
||||
{{ entry.name }} = {{ entry.value }}
|
||||
{% if entry.comment %}
|
||||
{{ entry.comment }}
|
||||
|
||||
{% endif %}
|
||||
{{ entry.name }} = {{ entry.value }}
|
||||
{% endfor %}
|
||||
|
||||
|
||||
@ -45,10 +46,11 @@ class {{ message.py_name }}(betterproto.Message):
|
||||
|
||||
{% endif %}
|
||||
{% for field in message.fields %}
|
||||
{{ field.get_field_string() }}
|
||||
{% if field.comment %}
|
||||
{{ field.comment }}
|
||||
|
||||
{% endif %}
|
||||
{{ field.get_field_string() }}
|
||||
{% endfor %}
|
||||
{% if not message.fields %}
|
||||
pass
|
||||
|
Loading…
x
Reference in New Issue
Block a user