Skip to content

Commit

Permalink
ENH: numpydoc: deal with duplicated signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
pv committed Feb 16, 2013
1 parent c5cb18f commit a4cd4ff
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
18 changes: 11 additions & 7 deletions doc/sphinxext/docscrape.py
Expand Up @@ -265,13 +265,17 @@ def _parse_summary(self):
if self._is_at_section():
return

summary = self._doc.read_to_next_empty_line()
summary_str = " ".join([s.strip() for s in summary]).strip()
if re.compile('^([\w., ]+=)?\s*[\w\.]+\(.*\)$').match(summary_str):
self['Signature'] = summary_str
if not self._is_at_section():
self['Summary'] = self._doc.read_to_next_empty_line()
else:
# If several signatures present, take the last one
while True:
summary = self._doc.read_to_next_empty_line()
summary_str = " ".join([s.strip() for s in summary]).strip()
if re.compile('^([\w., ]+=)?\s*[\w\.]+\(.*\)$').match(summary_str):
self['Signature'] = summary_str
if not self._is_at_section():
continue
break

if summary is not None:
self['Summary'] = summary

if not self._is_at_section():
Expand Down
14 changes: 14 additions & 0 deletions doc/sphinxext/tests/test_docscrape.py
Expand Up @@ -609,6 +609,20 @@ def ham(self, c, d):
if cls is SphinxClassDoc:
assert '.. autosummary::' in str(doc), str(doc)

def test_duplicate_signature():
# Duplicate function signatures occur e.g. in ufuncs, when the
# automatic mechanism adds one, and a more detailed comes from the
# docstring itself.

doc = NumpyDocString(
"""
z(x1, x2)
z(a, theta)
""")

assert doc['Signature'].strip() == 'z(a, theta)'

if __name__ == "__main__":
import nose
nose.run()
Expand Down

0 comments on commit a4cd4ff

Please sign in to comment.