Skip to content

Commit e8cdce1

Browse files
Put Literal args in code blocks (#288)
* Put Literal args in code blocks * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 2d559cf commit e8cdce1

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/sphinx_autodoc_typehints/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def format_annotation(annotation: Any, config: Config) -> str: # noqa: C901 # t
181181
fmt = [format_annotation(arg, config) for arg in args]
182182
formatted_args = f"\\[\\[{', '.join(fmt[:-1])}], {fmt[-1]}]"
183183
elif full_name == "typing.Literal":
184-
formatted_args = f"\\[{', '.join(repr(arg) for arg in args)}]"
184+
formatted_args = "\\[{}]".format(", ".join(f"``{arg!r}``" for arg in args))
185185
elif full_name == "types.UnionType":
186186
return " | ".join([format_annotation(arg, config) for arg in args])
187187

tests/test_sphinx_autodoc_typehints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ def test_format_annotation(inv: Inventory, annotation: Any, expected_result: str
360360
[
361361
("ClassVar", int, ":py:data:`~typing.ClassVar`\\[:py:class:`int`]"),
362362
("NoReturn", None, ":py:data:`~typing.NoReturn`"),
363-
("Literal", ("a", 1), ":py:data:`~typing.Literal`\\['a', 1]"),
363+
("Literal", ("a", 1), ":py:data:`~typing.Literal`\\[``'a'``, ``1``]"),
364364
("Type", None, ":py:class:`~typing.Type`"),
365365
("Type", (A,), f":py:class:`~typing.Type`\\[:py:class:`~{__name__}.A`]"),
366366
],

0 commit comments

Comments
 (0)