Repository: tox-dev/sphinx-autodoc-typehints
Pull request #466 (2024-07-08 16:50:07)

[pre-commit.ci] pre-commit autoupdate
<!--pre-commit.ci start-->
updates:
- [github.com/python-jsonschema/check-jsonschema: 0.28.6 → 0.29.0](https://github.com/python-jsonschema/check-jsonschema/compare/0.28.6...0.29.0)
- [github.com/tox-dev/pyproject-fmt: 2.1.3 → 2.1.4](https://github.com/tox-dev/pyproject-fmt/compare/2.1.3...2.1.4)
- [github.com/astral-sh/ruff-pre-commit: v0.5.0 → v0.5.2](https://github.com/astral-sh/ruff-pre-commit/compare/v0.5.0...v0.5.2)
<!--pre-commit.ci end-->


Patch:
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index d8fe41e..a49c60f 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -5,7 +5,7 @@ repos:
       - id: end-of-file-fixer
       - id: trailing-whitespace
   - repo: https://github.com/python-jsonschema/check-jsonschema
-    rev: 0.28.6
+    rev: 0.29.0
     hooks:
       - id: check-github-workflows
         args: [ "--verbose" ]
@@ -20,12 +20,12 @@ repos:
       - id: tox-ini-fmt
         args: ["-p", "fix"]
   - repo: https://github.com/tox-dev/pyproject-fmt
-    rev: "2.1.3"
+    rev: "2.1.4"
     hooks:
       - id: pyproject-fmt
         additional_dependencies: ["tox>=4.14.2"]
   - repo: https://github.com/astral-sh/ruff-pre-commit
-    rev: "v0.5.0"
+    rev: "v0.5.2"
     hooks:
       - id: ruff-format
       - id: ruff
diff --git a/src/sphinx_autodoc_typehints/__init__.py b/src/sphinx_autodoc_typehints/__init__.py
index 6002019..824f458 100644
--- a/src/sphinx_autodoc_typehints/__init__.py
+++ b/src/sphinx_autodoc_typehints/__init__.py
@@ -849,7 +849,7 @@ 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
@@ -857,7 +857,7 @@ def get_insert_index(app: Sphinx, lines: list[str]) -> InsertIndexInfo | None:
         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


Test patch:
diff --git a/tests/conftest.py b/tests/conftest.py
index 89d46b0..a50bc0d 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -45,7 +45,7 @@ def _remove_sphinx_projects(sphinx_test_tempdir: path) -> None:
             pass
 
 
-@pytest.fixture()
+@pytest.fixture
 def rootdir() -> path:
     return path(str(Path(__file__).parent) or ".").abspath() / "roots"
 
diff --git a/tests/test_integration.py b/tests/test_integration.py
index 8d732d9..a9aec4c 100644
--- a/tests/test_integration.py
+++ b/tests/test_integration.py
@@ -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 = {