Skip to content

Commit 2f863c2

Browse files
committed
Fix NewType first argument is reference
Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
1 parent 5cc10ef commit 2f863c2

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.13.1
4+
5+
- Fixed ``NewType`` inserts a reference as first argument instead of a string
6+
37
## 1.13.0
48

59
- Dropped Python 3.6 support

src/sphinx_autodoc_typehints/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def format_annotation(annotation, fully_qualified: bool = False, simplify_option
126126

127127
# Some types require special handling
128128
if full_name == "typing.NewType":
129-
args_format = f"\\(:py:data:`~{annotation.__name__}`, {{}})"
129+
args_format = f"\\(``{annotation.__name__}``, {{}})"
130130
role = "class" if sys.version_info >= (3, 10) else "func"
131131
elif full_name == "typing.Optional":
132132
args = tuple(x for x in args if x is not type(None)) # noqa: E721

tests/test_sphinx_autodoc_typehints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def test_parse_annotation(annotation, module, class_name, args):
182182
(D, ":py:class:`~%s.D`" % __name__),
183183
(E, ":py:class:`~%s.E`" % __name__),
184184
(E[int], ":py:class:`~%s.E`\\[:py:class:`int`]" % __name__),
185-
(W, f':py:{"class" if PY310_PLUS else "func"}:' f"`~typing.NewType`\\(:py:data:`~W`, :py:class:`str`)"),
185+
(W, f':py:{"class" if PY310_PLUS else "func"}:' f"`~typing.NewType`\\(``W``, :py:class:`str`)"),
186186
],
187187
)
188188
def test_format_annotation(inv, annotation, expected_result):

0 commit comments

Comments
 (0)