diff options
author | Pauli Virtanen <pav@iki.fi> | 2012-12-09 19:38:53 +0200 |
---|---|---|
committer | Pauli Virtanen <pav@iki.fi> | 2013-02-16 17:28:28 +0200 |
commit | a4cd4ffd52b4b60df4e8752ea202862e2c386589 (patch) | |
tree | dd09d7f81045e055a4b32f82e780895f8a09c242 /doc | |
parent | c5cb18f9486c5e6291e476890a3b6bef1424062c (diff) | |
download | numpy-a4cd4ffd52b4b60df4e8752ea202862e2c386589.tar.gz |
ENH: numpydoc: deal with duplicated signatures
Diffstat (limited to 'doc')
-rw-r--r-- | doc/sphinxext/docscrape.py | 18 | ||||
-rw-r--r-- | doc/sphinxext/tests/test_docscrape.py | 14 |
2 files changed, 25 insertions, 7 deletions
diff --git a/doc/sphinxext/docscrape.py b/doc/sphinxext/docscrape.py index bbd3fcacc..b492b1ab8 100644 --- a/doc/sphinxext/docscrape.py +++ b/doc/sphinxext/docscrape.py @@ -265,13 +265,17 @@ class NumpyDocString(object): 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(): diff --git a/doc/sphinxext/tests/test_docscrape.py b/doc/sphinxext/tests/test_docscrape.py index 6fab79832..2454d27f5 100644 --- a/doc/sphinxext/tests/test_docscrape.py +++ b/doc/sphinxext/tests/test_docscrape.py @@ -609,6 +609,20 @@ def test_class_members(): 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() |