Permalink
Browse files

DocumentationComment.py: Add blankline padding

`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 ffba8311b20a6dca26a561db0870f667abb79270
@@ -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):
@@ -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
@@ -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):
@@ -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)
@@ -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
@@ -20,6 +25,7 @@ def get_55():
this is intended.
"""
""" Docstring inline with triple quotes.
Continues here. """
@@ -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):
@@ -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.
@@ -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.

0 comments on commit ffba831

Please sign in to comment.