Skip to content

Commit

Permalink
Fix NewType first argument is reference
Browse files Browse the repository at this point in the history
Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
  • Loading branch information
gaborbernat committed Jan 4, 2022
1 parent 5cc10ef commit 2f863c2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/sphinx_autodoc_typehints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sphinx_autodoc_typehints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 2f863c2

Please sign in to comment.