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
|
sci_loc.leading_comments.strip().replace("\n", ""), width=79 - indent
|
||||||
)
|
)
|
||||||
|
|
||||||
if path[-2] == 2 and path[-4] != 6:
|
# This is a field, message, enum, service, or method
|
||||||
# This is a field
|
if len(lines) == 1 and len(lines[0]) < 79 - indent - 6:
|
||||||
return f"{pad}# " + f"\n{pad}# ".join(lines)
|
lines[0] = lines[0].strip('"')
|
||||||
|
return f'{pad}"""{lines[0]}"""'
|
||||||
else:
|
else:
|
||||||
# This is a message, enum, service, or method
|
joined = f"\n{pad}".join(lines)
|
||||||
if len(lines) == 1 and len(lines[0]) < 79 - indent - 6:
|
return f'{pad}"""\n{pad}{joined}\n{pad}"""'
|
||||||
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}"""'
|
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
@ -28,10 +28,11 @@ class {{ enum.py_name }}(betterproto.Enum):
|
|||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% for entry in enum.entries %}
|
{% for entry in enum.entries %}
|
||||||
|
{{ entry.name }} = {{ entry.value }}
|
||||||
{% if entry.comment %}
|
{% if entry.comment %}
|
||||||
{{ entry.comment }}
|
{{ entry.comment }}
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ entry.name }} = {{ entry.value }}
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
|
||||||
@ -45,10 +46,11 @@ class {{ message.py_name }}(betterproto.Message):
|
|||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% for field in message.fields %}
|
{% for field in message.fields %}
|
||||||
|
{{ field.get_field_string() }}
|
||||||
{% if field.comment %}
|
{% if field.comment %}
|
||||||
{{ field.comment }}
|
{{ field.comment }}
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ field.get_field_string() }}
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if not message.fields %}
|
{% if not message.fields %}
|
||||||
pass
|
pass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user