Skip to content

Commit

Permalink
DocumentationComment.py: Add blankline padding
Browse files Browse the repository at this point in the history
`assemble()` now adds a blank line before or after
docstring based on top_padding and bottom_padding.

Closes #4200
  • Loading branch information
damngamerz committed Jul 24, 2017
1 parent fbb71a1 commit ffba831
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
13 changes: 9 additions & 4 deletions coalib/bearlib/languages/documentation/DocumentationComment.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class DocumentationComment:
ExceptionValue = namedtuple('ExceptionValue', 'name, desc')
ReturnValue = namedtuple('ReturnValue', 'desc')
Description = namedtuple('Description', 'desc')
top_padding = 0
bottom_padding = 0

def __init__(self, documentation, docstyle_definition,
indent, marker, position):
Expand Down Expand Up @@ -275,7 +277,10 @@ def assemble(self):
assembled += ''.join('\n' if line == '\n' and not self.marker[1]
else self.indent + self.marker[1] + line
for line in lines[1:])
return (assembled if self.marker[1] == self.marker[2] else
(assembled +
(self.indent if lines[-1][-1] == '\n' else '') +
self.marker[2]))
assembled = (assembled if self.marker[1] == self.marker[2] else
(assembled +
(self.indent if lines[-1][-1] == '\n' else '') +
self.marker[2]))
assembled = ('\n' * self.top_padding + assembled +
'\n' * self.bottom_padding)
return assembled
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ def test_python_assembly(self):
docs = ''.join(data)

for doc in DocBaseClass.extract(data, 'python', 'default'):
doc.bottom_padding = 2
doc.assemble.cache_clear()
self.assertIn(doc.assemble(), docs)

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

for doc in DocBaseClass.extract(data, 'c', 'doxygen'):
doc.top_padding = 1
doc.assemble.cache_clear()
self.assertIn(doc.assemble(), docs)
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
Some more foobar-like text.
"""


def foobar_explosion(radius):
"""
A nice and neat way of documenting code.
:param radius: The explosion radius. """


def get_55():
"""A function that returns 55."""


return 55
return get_55() * radius

Expand All @@ -20,6 +25,7 @@ def get_55():
this is intended.
"""


""" Docstring inline with triple quotes.
Continues here. """

Expand All @@ -36,6 +42,8 @@ def best_docstring(param1, param2):
:return: Long Return Description That Makes No Sense And Will
Cut to the Next Line.
"""


return None

def docstring_find(filename):
Expand All @@ -50,6 +58,7 @@ def docstring_find(filename):
:return: returns all possible docstrings in a file
"""


def foobar_triangle(side_A, side_B, side_C):
"""
This returns perimeter of a triangle.
Expand All @@ -63,6 +72,8 @@ def foobar_triangle(side_A, side_B, side_C):
:return: returns perimeter
"""


return side_A + side_B + side_C

# This example of triple quote string literal is ignored.
Expand Down

0 comments on commit ffba831

Please sign in to comment.