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(
633
633
return
634
634
formatted_annotation = format_annotation (type_hints ["return" ], app .config )
635
635
insert_index = len (lines )
636
+ extra_newline = False
636
637
for at , line in enumerate (lines ):
637
638
if line .startswith (":rtype:" ):
638
639
insert_index = None
@@ -643,16 +644,21 @@ def _inject_types_to_docstring(
643
644
break
644
645
insert_index = at
645
646
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.
647
648
insert_index = at
649
+ extra_newline = True
648
650
break
649
651
650
652
if insert_index is not None and app .config .typehints_document_rtype :
651
653
if insert_index == len (lines ): # ensure that :rtype: doesn't get joined with a paragraph of text
652
654
lines .append ("" )
653
655
insert_index += 1
654
656
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 )
656
662
else :
657
663
line = lines [insert_index ]
658
664
lines [insert_index ] = f":return: { formatted_annotation } --{ line [line .find (' ' ):]} "
You can’t perform that action at this time.
0 commit comments