Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions numpydoc/docscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,12 +459,20 @@ def _str_see_also(self, func_role):
def _str_index(self):
idx = self['index']
out = []
out += ['.. index:: %s' % idx.get('default', '')]
output_index = False
default_index = idx.get('default', '')
if len(default_index):
output_index = True
out += ['.. index:: %s' % default_index]
for section, references in idx.items():
if section == 'default':
continue
output_index = True
out += [' :%s: %s' % (section, ', '.join(references))]
return out
if output_index:
return out
else:
return ''

def __str__(self, func_role=''):
out = []
Expand Down
16 changes: 16 additions & 0 deletions numpydoc/tests/test_docscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,22 @@ def test_yield_str():
.. index:: """)


def test_no_index_in_str():
assert "index" not in str(NumpyDocString("""Test idx

"""))

assert "index" in str(NumpyDocString("""Test idx

.. index :: random
"""))

assert "index" in str(NumpyDocString("""Test idx

.. index ::
foo
"""))

def test_sphinx_str():
sphinx_doc = SphinxDocString(doc_txt)
line_by_line_compare(str(sphinx_doc),
Expand Down