From 2f863c20f83bb789610982375cb76b3c45bb787e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Tue, 4 Jan 2022 18:45:39 +0000 Subject: [PATCH] Fix NewType first argument is reference MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bernát Gábor --- CHANGELOG.md | 4 ++++ src/sphinx_autodoc_typehints/__init__.py | 2 +- tests/test_sphinx_autodoc_typehints.py | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77fa19b3..8a7e4186 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.13.1 + +- Fixed ``NewType`` inserts a reference as first argument instead of a string + ## 1.13.0 - Dropped Python 3.6 support diff --git a/src/sphinx_autodoc_typehints/__init__.py b/src/sphinx_autodoc_typehints/__init__.py index 8a98122e..c05b9669 100644 --- a/src/sphinx_autodoc_typehints/__init__.py +++ b/src/sphinx_autodoc_typehints/__init__.py @@ -126,7 +126,7 @@ def format_annotation(annotation, fully_qualified: bool = False, simplify_option # Some types require special handling if full_name == "typing.NewType": - args_format = f"\\(:py:data:`~{annotation.__name__}`, {{}})" + args_format = f"\\(``{annotation.__name__}``, {{}})" role = "class" if sys.version_info >= (3, 10) else "func" elif full_name == "typing.Optional": args = tuple(x for x in args if x is not type(None)) # noqa: E721 diff --git a/tests/test_sphinx_autodoc_typehints.py b/tests/test_sphinx_autodoc_typehints.py index 2790a84a..80283d99 100644 --- a/tests/test_sphinx_autodoc_typehints.py +++ b/tests/test_sphinx_autodoc_typehints.py @@ -182,7 +182,7 @@ def test_parse_annotation(annotation, module, class_name, args): (D, ":py:class:`~%s.D`" % __name__), (E, ":py:class:`~%s.E`" % __name__), (E[int], ":py:class:`~%s.E`\\[:py:class:`int`]" % __name__), - (W, f':py:{"class" if PY310_PLUS else "func"}:' f"`~typing.NewType`\\(:py:data:`~W`, :py:class:`str`)"), + (W, f':py:{"class" if PY310_PLUS else "func"}:' f"`~typing.NewType`\\(``W``, :py:class:`str`)"), ], ) def test_format_annotation(inv, annotation, expected_result):