Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve issue 305 #307

Merged
merged 4 commits into from Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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