File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -464,12 +464,20 @@ def _str_see_also(self, func_role):
464464 def _str_index (self ):
465465 idx = self ['index' ]
466466 out = []
467- out += ['.. index:: %s' % idx .get ('default' , '' )]
467+ output_index = False
468+ default_index = idx .get ('default' , '' )
469+ if default_index :
470+ output_index = True
471+ out += ['.. index:: %s' % default_index ]
468472 for section , references in idx .items ():
469473 if section == 'default' :
470474 continue
475+ output_index = True
471476 out += [' :%s: %s' % (section , ', ' .join (references ))]
472- return out
477+ if output_index :
478+ return out
479+ else :
480+ return ''
473481
474482 def __str__ (self , func_role = '' ):
475483 out = []
Original file line number Diff line number Diff line change @@ -468,6 +468,22 @@ def test_yield_str():
468468.. index:: """ )
469469
470470
471+ def test_no_index_in_str ():
472+ assert "index" not in str (NumpyDocString ("""Test idx
473+
474+ """ ))
475+
476+ assert "index" in str (NumpyDocString ("""Test idx
477+
478+ .. index :: random
479+ """ ))
480+
481+ assert "index" in str (NumpyDocString ("""Test idx
482+
483+ .. index ::
484+ foo
485+ """ ))
486+
471487def test_sphinx_str ():
472488 sphinx_doc = SphinxDocString (doc_txt )
473489 line_by_line_compare (str (sphinx_doc ),
You can’t perform that action at this time.
0 commit comments