Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/sphinx_autodoc_typehints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def format_annotation(annotation: Any, config: Config) -> str: # noqa: C901 # t
fmt = [format_annotation(arg, config) for arg in args]
formatted_args = f"\\[\\[{', '.join(fmt[:-1])}], {fmt[-1]}]"
elif full_name == "typing.Literal":
formatted_args = f"\\[{', '.join(repr(arg) for arg in args)}]"
formatted_args = "\\[{}]".format(", ".join(f"``{arg!r}``" for arg in args))
elif full_name == "types.UnionType":
return " | ".join([format_annotation(arg, config) for arg in args])

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 @@ -359,7 +359,7 @@ def test_format_annotation(inv: Inventory, annotation: Any, expected_result: str
[
("ClassVar", int, ":py:data:`~typing.ClassVar`\\[:py:class:`int`]"),
("NoReturn", None, ":py:data:`~typing.NoReturn`"),
("Literal", ("a", 1), ":py:data:`~typing.Literal`\\['a', 1]"),
("Literal", ("a", 1), ":py:data:`~typing.Literal`\\[``'a'``, ``1``]"),
("Type", None, ":py:class:`~typing.Type`"),
("Type", (A,), f":py:class:`~typing.Type`\\[:py:class:`~{__name__}.A`]"),
],
Expand Down