Skip to content

Commit

Permalink
Resolve issue 305 (#307)
Browse files Browse the repository at this point in the history
Resolves #305
  • Loading branch information
hoodmane committed Jan 20, 2023
1 parent fb30e40 commit d823f99
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
4 changes: 4 additions & 0 deletions 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
Expand Down
3 changes: 3 additions & 0 deletions src/sphinx_autodoc_typehints/__init__.py
Expand Up @@ -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("")
Expand Down
37 changes: 36 additions & 1 deletion tests/test_integration.py
Expand Up @@ -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.{}
Expand Down Expand Up @@ -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

0 comments on commit d823f99

Please sign in to comment.