Skip to content

Commit

Permalink
Fix rendering when docstring starst with a directive (#468)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoodmane authored Jul 17, 2024
1 parent fdad0d7 commit a427536
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/sphinx_autodoc_typehints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -849,15 +849,15 @@ def get_insert_index(app: Sphinx, lines: list[str]) -> InsertIndexInfo | None:
# at end. (I don't know of any input where this happens.)
next_sibling = child.next_node(descend=False, siblings=True)
line_no = node_line_no(next_sibling) if next_sibling else None
at = line_no - 2 if line_no else len(lines)
at = max(line_no - 2, 0) if line_no else len(lines)
return InsertIndexInfo(insert_index=at, found_param=True)

# 4. Insert before examples
for child in doc.children:
if tag_name(child) in {"literal_block", "paragraph", "field_list"}:
continue
line_no = node_line_no(child)
at = line_no - 2 if line_no else len(lines)
at = max(line_no - 2, 0) if line_no else len(lines)
return InsertIndexInfo(insert_index=at, found_directive=True)

# 5. Otherwise, insert at end
Expand Down
18 changes: 18 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,24 @@ def docstring_with_multiline_note_after_params_epilog_replace(param: int) -> Non
"""


@expected(
"""
mod.docstring_with_see_also()
Return type:
"str"
See also: more info at <https://example.com>`_.
"""
)
def docstring_with_see_also() -> str:
"""
.. seealso:: more info at <https://example.com>`_.
"""
return ""


# Config settings for each test run.
# Config Name: Sphinx Options as Dict.
configs = {
Expand Down

0 comments on commit a427536

Please sign in to comment.