File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -391,12 +391,14 @@ def insert_try_examples_directive(lines, **options):
391391 lines [right_index ]
392392 ):
393393 right_index += 1
394- if "!! processed by numpydoc !!" in lines [right_index ]:
394+
395+ # Check if we've reached the end of the docstring
396+ if right_index < len (lines ) and "!! processed by numpydoc !!" in lines [right_index ]:
395397 # Sometimes the .. appears on an earlier line than !! processed by numpydoc !!
396398 if not re .search (
397399 r"\.\.\s+\!\! processed by numpy doc \!\!" , lines [right_index ]
398400 ):
399- while lines [right_index ].strip () != ".." :
401+ while right_index > 0 and lines [right_index ].strip () != ".." :
400402 right_index -= 1
401403
402404 # Add the ".. try_examples::" directive and indent the content of the Examples section
@@ -406,8 +408,10 @@ def insert_try_examples_directive(lines, **options):
406408 + [f" :{ key } : { value } " for key , value in options .items ()]
407409 + ["" ]
408410 + [" " + line for line in lines [left_index :right_index ]]
409- + ["" ]
410- + lines [right_index :]
411411 )
412412
413+ # Append the remainder of the docstring, if there is any
414+ if right_index < len (lines ):
415+ new_lines += ["" ] + lines [right_index :]
416+
413417 return new_lines
You can’t perform that action at this time.
0 commit comments