From cc188f4244576b6adf075a9949e75bde5ad1edaa Mon Sep 17 00:00:00 2001 From: user Date: Wed, 16 Apr 2025 12:28:01 -0400 Subject: [PATCH] Place rtype after directive Closes #535 --- src/sphinx_autodoc_typehints/__init__.py | 2 ++ tests/test_integration.py | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/sphinx_autodoc_typehints/__init__.py b/src/sphinx_autodoc_typehints/__init__.py index 432fdf4..bb879d3 100644 --- a/src/sphinx_autodoc_typehints/__init__.py +++ b/src/sphinx_autodoc_typehints/__init__.py @@ -899,6 +899,8 @@ def get_insert_index(app: Sphinx, lines: list[str]) -> InsertIndexInfo | None: continue line_no = node_line_no(child) at = max(line_no - 2, 0) if line_no else len(lines) + if lines[at - 1]: # skip if something on this line + break return InsertIndexInfo(insert_index=at, found_directive=True) # 5. Otherwise, insert at end diff --git a/tests/test_integration.py b/tests/test_integration.py index 900d585..99bf232 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -1397,15 +1397,19 @@ def docstring_with_multiline_note_after_params_epilog_replace(param: int) -> Non """ mod.docstring_with_see_also() - Return type: - "str" + Test See also: more info at `_. + Return type: + "str" + """ ) def docstring_with_see_also() -> str: """ + Test + .. seealso:: more info at `_. """ return ""