Skip to content

Commit ffba831

Browse files
committed
DocumentationComment.py: Add blankline padding
`assemble()` now adds a blank line before or after docstring based on top_padding and bottom_padding. Closes #4200
1 parent fbb71a1 commit ffba831

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

coalib/bearlib/languages/documentation/DocumentationComment.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class DocumentationComment:
1717
ExceptionValue = namedtuple('ExceptionValue', 'name, desc')
1818
ReturnValue = namedtuple('ReturnValue', 'desc')
1919
Description = namedtuple('Description', 'desc')
20+
top_padding = 0
21+
bottom_padding = 0
2022

2123
def __init__(self, documentation, docstyle_definition,
2224
indent, marker, position):
@@ -275,7 +277,10 @@ def assemble(self):
275277
assembled += ''.join('\n' if line == '\n' and not self.marker[1]
276278
else self.indent + self.marker[1] + line
277279
for line in lines[1:])
278-
return (assembled if self.marker[1] == self.marker[2] else
279-
(assembled +
280-
(self.indent if lines[-1][-1] == '\n' else '') +
281-
self.marker[2]))
280+
assembled = (assembled if self.marker[1] == self.marker[2] else
281+
(assembled +
282+
(self.indent if lines[-1][-1] == '\n' else '') +
283+
self.marker[2]))
284+
assembled = ('\n' * self.top_padding + assembled +
285+
'\n' * self.bottom_padding)
286+
return assembled

tests/bearlib/languages/documentation/DocumentationCommentTest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ def test_python_assembly(self):
279279
docs = ''.join(data)
280280

281281
for doc in DocBaseClass.extract(data, 'python', 'default'):
282+
doc.bottom_padding = 2
283+
doc.assemble.cache_clear()
282284
self.assertIn(doc.assemble(), docs)
283285

284286
def test_doxygen_assembly(self):
@@ -293,4 +295,6 @@ def test_c_assembly(self):
293295
docs = ''.join(data)
294296

295297
for doc in DocBaseClass.extract(data, 'c', 'doxygen'):
298+
doc.top_padding = 1
299+
doc.assemble.cache_clear()
296300
self.assertIn(doc.assemble(), docs)

tests/bearlib/languages/documentation/documentation_extraction_testdata/default.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44
Some more foobar-like text.
55
"""
66

7+
78
def foobar_explosion(radius):
89
"""
910
A nice and neat way of documenting code.
1011
:param radius: The explosion radius. """
12+
13+
1114
def get_55():
1215
"""A function that returns 55."""
16+
17+
1318
return 55
1419
return get_55() * radius
1520

@@ -20,6 +25,7 @@ def get_55():
2025
this is intended.
2126
"""
2227

28+
2329
""" Docstring inline with triple quotes.
2430
Continues here. """
2531

@@ -36,6 +42,8 @@ def best_docstring(param1, param2):
3642
:return: Long Return Description That Makes No Sense And Will
3743
Cut to the Next Line.
3844
"""
45+
46+
3947
return None
4048

4149
def docstring_find(filename):
@@ -50,6 +58,7 @@ def docstring_find(filename):
5058
:return: returns all possible docstrings in a file
5159
"""
5260

61+
5362
def foobar_triangle(side_A, side_B, side_C):
5463
"""
5564
This returns perimeter of a triangle.
@@ -63,6 +72,8 @@ def foobar_triangle(side_A, side_B, side_C):
6372
6473
:return: returns perimeter
6574
"""
75+
76+
6677
return side_A + side_B + side_C
6778

6879
# This example of triple quote string literal is ignored.

0 commit comments

Comments
 (0)