diff --git a/CHANGELOG.md b/CHANGELOG.md index 73824f79..c2f74891 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [Unreleased] + +- Fix a `Field list ends without a blank line` warning (issue 305). + ## 1.21.5 - More robust determination of rtype location / fix issue 302 diff --git a/src/sphinx_autodoc_typehints/__init__.py b/src/sphinx_autodoc_typehints/__init__.py index ff59a952..c87d0d27 100644 --- a/src/sphinx_autodoc_typehints/__init__.py +++ b/src/sphinx_autodoc_typehints/__init__.py @@ -758,6 +758,9 @@ def _inject_rtype( formatted_annotation = format_annotation(type_hints["return"], app.config) + if r.found_param and insert_index < len(lines) and lines[insert_index].strip() != "": + insert_index -= 1 + if insert_index == len(lines) and not r.found_param: # ensure that :rtype: doesn't get joined with a paragraph of text lines.append("") diff --git a/tests/test_integration.py b/tests/test_integration.py index 08854586..2907dbf8 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -874,6 +874,41 @@ def func_with_definition_list() -> int: # See https://github.com/tox-dev/sphinx-autodoc-typehints/issues/302 +@expected( + """\ +mod.decorator_2(f) + + Run the decorated function with *asyncio.run*. + + Parameters: + **f** ("Any") -- The function to wrap. + + Return type: + "Any" + + -[ Examples ]- + + A +""" +) +def decorator_2(f: Any) -> Any: + """Run the decorated function with `asyncio.run`. + + Parameters + ---------- + f + The function to wrap. + + Examples + -------- + + .. code-block:: python + + A + """ + f + + AUTO_FUNCTION = ".. autofunction:: mod.{}" AUTO_CLASS = """\ .. autoclass:: mod.{} @@ -914,5 +949,5 @@ def test_integration(app: SphinxTestApp, status: StringIO, warning: StringIO, mo try: assert result.strip() == dedent(expected).strip() except Exception: - print("Result was:\n", result, "\n\n") + print(f"Result was:\n{result}\n\n") raise