Skip to content

Commit

Permalink
Fix issue #42 - "End of docstring"
Browse files Browse the repository at this point in the history
  • Loading branch information
joeced committed Nov 28, 2017
1 parent 528f076 commit 83ca14d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
14 changes: 11 additions & 3 deletions sphinxcontrib/mat_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,12 +484,20 @@ def __init__(self, name, modname, tokens):
except IndexError:
docstring = None
while docstring and docstring[0] is Token.Comment:
self.docstring += docstring[1].lstrip('%') + '\n' # concatenate
self.docstring += docstring[1].lstrip('%')
# Get newline if it exists and append to docstring
try:
wht = tks.pop() # skip whitespace
wht = tks.pop() # We expect a newline
except IndexError:
break
while wht in list(zip((Token.Text,) * 3, (' ', '\t', '\n'))):
if wht[0] == Token.Text and wht[1] == '\n':
self.docstring += '\n'
# Skip whitespace
try:
wht = tks.pop() # We expect a newline
except IndexError:
break
while wht in list(zip((Token.Text,) * 3, (' ', '\t'))):
try:
wht = tks.pop()
except IndexError:
Expand Down
1 change: 1 addition & 0 deletions tests/test_data/myfun.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
% :param a2: another input
% :returns: ``[o1, o2, o3]`` some outputs

% Check input args
if nargin<1
a1 = 0;
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function [output] = f_with_comment_after_docstring(input)
% Tests a function with comments after docstring

% A comment
output = 'output';
with = 'with';
ellipsis = 'ellipsis';
12 changes: 12 additions & 0 deletions tests/test_mat_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ def test_property_with_ellipsis():
assert C.docstring == " using end inside array"
return ellipsis_class, A, B, C

def test_function_with_comment_after_docstring():
test_data = doc.MatObject.matlabify('test_data')
test_submodule = test_data.getter('test_submodule')
assert isinstance(test_submodule, doc.MatModule)
assert test_submodule.__package__ == 'test_data.test_submodule'
f = test_submodule.getter('f_with_comment_after_docstring')
assert f.args == ['input']
assert f.retv == ['output']
assert f.docstring == " Tests a function with comments after docstring\n"


if __name__ == '__main__':
f1 = test_ellipsis_after_equals
print(f1.__name__)
Expand Down Expand Up @@ -157,3 +168,4 @@ def test_property_with_ellipsis():
pprint(A.__dict__)
pprint(B.__dict__)
pprint(C.__dict__)
test_function_with_comment_after_docstring()

0 comments on commit 83ca14d

Please sign in to comment.