File tree 2 files changed +26
-2
lines changed 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):
464
464
def _str_index (self ):
465
465
idx = self ['index' ]
466
466
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 ]
468
472
for section , references in idx .items ():
469
473
if section == 'default' :
470
474
continue
475
+ output_index = True
471
476
out += [' :%s: %s' % (section , ', ' .join (references ))]
472
- return out
477
+ if output_index :
478
+ return out
479
+ else :
480
+ return ''
473
481
474
482
def __str__ (self , func_role = '' ):
475
483
out = []
Original file line number Diff line number Diff line change @@ -468,6 +468,22 @@ def test_yield_str():
468
468
.. index:: """ )
469
469
470
470
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
+
471
487
def test_sphinx_str ():
472
488
sphinx_doc = SphinxDocString (doc_txt )
473
489
line_by_line_compare (str (sphinx_doc ),
You can’t perform that action at this time.
0 commit comments