File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
src/sphinx_autodoc_typehints Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -633,6 +633,7 @@ def _inject_types_to_docstring(
633633 return
634634 formatted_annotation = format_annotation (type_hints ["return" ], app .config )
635635 insert_index = len (lines )
636+ extra_newline = False
636637 for at , line in enumerate (lines ):
637638 if line .startswith (":rtype:" ):
638639 insert_index = None
@@ -643,16 +644,21 @@ def _inject_types_to_docstring(
643644 break
644645 insert_index = at
645646 elif line .startswith (".." ):
646- # Make sure that rtype comes before any usage or examples section
647+ # Make sure that rtype comes before any usage or examples section, with a blank line between.
647648 insert_index = at
649+ extra_newline = True
648650 break
649651
650652 if insert_index is not None and app .config .typehints_document_rtype :
651653 if insert_index == len (lines ): # ensure that :rtype: doesn't get joined with a paragraph of text
652654 lines .append ("" )
653655 insert_index += 1
654656 if app .config .typehints_use_rtype or insert_index == len (lines ):
655- lines .insert (insert_index , f":rtype: { formatted_annotation } " )
657+ line = f":rtype: { formatted_annotation } "
658+ if extra_newline :
659+ lines [insert_index :insert_index ] = [line , "\n " ]
660+ else :
661+ lines .insert (insert_index , line )
656662 else :
657663 line = lines [insert_index ]
658664 lines [insert_index ] = f":return: { formatted_annotation } --{ line [line .find (' ' ):]} "
You can’t perform that action at this time.
0 commit comments