Skip to content

Commit 9735dc6

Browse files
authored
ENH Add a css wrapper to generated types (#397)
1 parent 8d9d554 commit 9735dc6

File tree

3 files changed

+102
-65
lines changed

3 files changed

+102
-65
lines changed

src/sphinx_autodoc_typehints/__init__.py

+48-6
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
from dataclasses import dataclass
1212
from typing import TYPE_CHECKING, Any, AnyStr, Callable, ForwardRef, NewType, TypeVar, get_type_hints
1313

14+
from docutils import nodes
1415
from docutils.frontend import OptionParser
1516
from docutils.parsers.rst import Parser as RstParser
17+
from docutils.parsers.rst import states
1618
from docutils.utils import new_document
1719
from sphinx.ext.autodoc.mock import mock
18-
from sphinx.util import logging
20+
from sphinx.util import logging, rst
1921
from sphinx.util.inspect import signature as sphinx_signature
2022
from sphinx.util.inspect import stringify_signature
2123

@@ -209,7 +211,7 @@ def format_annotation(annotation: Any, config: Config) -> str: # noqa: C901, PL
209211
fully_qualified: bool = getattr(config, "typehints_fully_qualified", False)
210212
prefix = "" if fully_qualified or full_name == class_name else "~"
211213
role = "data" if module == "typing" and class_name in _PYDATA_ANNOTATIONS else "class"
212-
args_format = "\\[{}]"
214+
args_format = "\\ \\[{}]"
213215
formatted_args: str | None = ""
214216

215217
# Some types require special handling
@@ -242,9 +244,9 @@ def format_annotation(annotation: Any, config: Config) -> str: # noqa: C901, PL
242244
args = tuple(x for x in args if x is not type(None))
243245
elif full_name in ("typing.Callable", "collections.abc.Callable") and args and args[0] is not ...:
244246
fmt = [format_annotation(arg, config) for arg in args]
245-
formatted_args = f"\\[\\[{', '.join(fmt[:-1])}], {fmt[-1]}]"
247+
formatted_args = f"\\ \\[\\[{', '.join(fmt[:-1])}], {fmt[-1]}]"
246248
elif full_name == "typing.Literal":
247-
formatted_args = f"\\[{', '.join(f'``{arg!r}``' for arg in args)}]"
249+
formatted_args = f"\\ \\[{', '.join(f'``{arg!r}``' for arg in args)}]"
248250
elif full_name == "types.UnionType":
249251
return " | ".join([format_annotation(arg, config) for arg in args])
250252

@@ -724,7 +726,7 @@ def _inject_signature( # noqa: C901
724726
if annotation is None:
725727
type_annotation = f":type {arg_name}: "
726728
else:
727-
formatted_annotation = format_annotation(annotation, app.config)
729+
formatted_annotation = add_type_css_class(format_annotation(annotation, app.config))
728730
type_annotation = f":type {arg_name}: {formatted_annotation}"
729731

730732
if app.config.typehints_defaults:
@@ -843,7 +845,7 @@ def _inject_rtype( # noqa: PLR0913
843845
if not app.config.typehints_use_rtype and r.found_return and " -- " in lines[insert_index]:
844846
return
845847

846-
formatted_annotation = format_annotation(type_hints["return"], app.config)
848+
formatted_annotation = add_type_css_class(format_annotation(type_hints["return"], app.config))
847849

848850
if r.found_param and insert_index < len(lines) and lines[insert_index].strip():
849851
insert_index -= 1
@@ -874,6 +876,45 @@ def validate_config(app: Sphinx, env: BuildEnvironment, docnames: list[str]) ->
874876
raise ValueError(msg)
875877

876878

879+
def unescape(escaped: str) -> str:
880+
# For some reason the string we get has a bunch of null bytes in it??
881+
# Remove them...
882+
escaped = escaped.replace("\x00", "")
883+
# For some reason the extra slash before spaces gets lost between the .rst
884+
# source and when this directive is called. So don't replace "\<space>" =>
885+
# "<space>"
886+
return re.sub(r"\\([^ ])", r"\1", escaped)
887+
888+
889+
def add_type_css_class(type_rst: str) -> str:
890+
return f":sphinx_autodoc_typehints_type:`{rst.escape(type_rst)}`"
891+
892+
893+
def sphinx_autodoc_typehints_type_role(
894+
_role: str,
895+
_rawtext: str,
896+
text: str,
897+
_lineno: int,
898+
inliner: states.Inliner,
899+
_options: dict[str, Any] | None = None,
900+
_content: list[str] | None = None,
901+
) -> tuple[list[Node], list[Node]]:
902+
"""
903+
Add css tag around rendered type.
904+
905+
The body should be escaped rst. This renders its body as rst and wraps the
906+
result in <span class="sphinx_autodoc_typehints-type"> </span>
907+
"""
908+
unescaped = unescape(text)
909+
# the typestubs for docutils don't have any info about Inliner
910+
doc = new_document("", inliner.document.settings) # type: ignore[attr-defined]
911+
RstParser().parse(unescaped, doc)
912+
n = nodes.inline(text)
913+
n["classes"].append("sphinx_autodoc_typehints-type")
914+
n += doc.children[0].children
915+
return [n], []
916+
917+
877918
def setup(app: Sphinx) -> dict[str, bool]:
878919
app.add_config_value("always_document_param_types", False, "html") # noqa: FBT003
879920
app.add_config_value("typehints_fully_qualified", False, "env") # noqa: FBT003
@@ -884,6 +925,7 @@ def setup(app: Sphinx) -> dict[str, bool]:
884925
app.add_config_value("typehints_formatter", None, "env")
885926
app.add_config_value("typehints_use_signature", False, "env") # noqa: FBT003
886927
app.add_config_value("typehints_use_signature_return", False, "env") # noqa: FBT003
928+
app.add_role("sphinx_autodoc_typehints_type", sphinx_autodoc_typehints_type_role)
887929
app.connect("env-before-read-docs", validate_config) # config may be changed after “config-inited” event
888930
app.connect("autodoc-process-signature", process_signature)
889931
app.connect("autodoc-process-docstring", process_docstring)

tests/test_integration.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def function_with_escaped_default(x: str = "\b"): # noqa: ANN201, ARG001
326326
Function docstring.
327327
328328
Parameters:
329-
**x** (*a.b.c*) -- foo
329+
**x** (a.b.c) -- foo
330330
""",
331331
)
332332
def function_with_unresolvable_annotation(x: a.b.c): # noqa: ANN201, ARG001, F821

tests/test_sphinx_autodoc_typehints.py

+53-58
Original file line numberDiff line numberDiff line change
@@ -201,87 +201,87 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t
201201
(type, ":py:class:`type`"),
202202
(collections.abc.Callable, ":py:class:`~collections.abc.Callable`"),
203203
(Type, ":py:class:`~typing.Type`"),
204-
(Type[A], ":py:class:`~typing.Type`\\[:py:class:`~%s.A`]" % __name__),
204+
(Type[A], ":py:class:`~typing.Type`\\ \\[:py:class:`~%s.A`]" % __name__),
205205
(Any, ":py:data:`~typing.Any`"),
206206
(AnyStr, ":py:data:`~typing.AnyStr`"),
207-
(Generic[T], ":py:class:`~typing.Generic`\\[:py:class:`~typing.TypeVar`\\(``T``)]"),
207+
(Generic[T], ":py:class:`~typing.Generic`\\ \\[:py:class:`~typing.TypeVar`\\(``T``)]"),
208208
(Mapping, ":py:class:`~typing.Mapping`"),
209209
(
210210
Mapping[T, int], # type: ignore[valid-type]
211-
":py:class:`~typing.Mapping`\\[:py:class:`~typing.TypeVar`\\(``T``), :py:class:`int`]",
211+
":py:class:`~typing.Mapping`\\ \\[:py:class:`~typing.TypeVar`\\(``T``), :py:class:`int`]",
212212
),
213213
(
214214
Mapping[str, V_contra], # type: ignore[valid-type]
215-
":py:class:`~typing.Mapping`\\[:py:class:`str`, :py:class:`~typing.TypeVar`\\("
215+
":py:class:`~typing.Mapping`\\ \\[:py:class:`str`, :py:class:`~typing.TypeVar`\\("
216216
"``V_contra``, contravariant=True)]",
217217
),
218218
(
219219
Mapping[T, U_co], # type: ignore[valid-type]
220-
":py:class:`~typing.Mapping`\\[:py:class:`~typing.TypeVar`\\(``T``), "
220+
":py:class:`~typing.Mapping`\\ \\[:py:class:`~typing.TypeVar`\\(``T``), "
221221
":py:class:`~typing.TypeVar`\\(``U_co``, covariant=True)]",
222222
),
223-
(Mapping[str, bool], ":py:class:`~typing.Mapping`\\[:py:class:`str`, :py:class:`bool`]"),
223+
(Mapping[str, bool], ":py:class:`~typing.Mapping`\\ \\[:py:class:`str`, :py:class:`bool`]"),
224224
(Dict, ":py:class:`~typing.Dict`"),
225225
(
226226
Dict[T, int], # type: ignore[valid-type]
227-
":py:class:`~typing.Dict`\\[:py:class:`~typing.TypeVar`\\(``T``), :py:class:`int`]",
227+
":py:class:`~typing.Dict`\\ \\[:py:class:`~typing.TypeVar`\\(``T``), :py:class:`int`]",
228228
),
229229
(
230230
Dict[str, V_contra], # type: ignore[valid-type]
231-
":py:class:`~typing.Dict`\\[:py:class:`str`, :py:class:`~typing.TypeVar`\\(``V_contra``, contravariant=True)]",
231+
":py:class:`~typing.Dict`\\ \\[:py:class:`str`, :py:class:`~typing.TypeVar`\\(``V_contra``, contravariant=True)]", # noqa: E501
232232
),
233233
(
234234
Dict[T, U_co], # type: ignore[valid-type]
235-
":py:class:`~typing.Dict`\\[:py:class:`~typing.TypeVar`\\(``T``),"
235+
":py:class:`~typing.Dict`\\ \\[:py:class:`~typing.TypeVar`\\(``T``),"
236236
" :py:class:`~typing.TypeVar`\\(``U_co``, covariant=True)]",
237237
),
238-
(Dict[str, bool], ":py:class:`~typing.Dict`\\[:py:class:`str`, :py:class:`bool`]"),
238+
(Dict[str, bool], ":py:class:`~typing.Dict`\\ \\[:py:class:`str`, :py:class:`bool`]"),
239239
(Tuple, ":py:data:`~typing.Tuple`"),
240-
(Tuple[str, bool], ":py:data:`~typing.Tuple`\\[:py:class:`str`, :py:class:`bool`]"),
241-
(Tuple[int, int, int], ":py:data:`~typing.Tuple`\\[:py:class:`int`, :py:class:`int`, :py:class:`int`]"),
242-
(Tuple[str, ...], ":py:data:`~typing.Tuple`\\[:py:class:`str`, :py:data:`...<Ellipsis>`]"),
240+
(Tuple[str, bool], ":py:data:`~typing.Tuple`\\ \\[:py:class:`str`, :py:class:`bool`]"),
241+
(Tuple[int, int, int], ":py:data:`~typing.Tuple`\\ \\[:py:class:`int`, :py:class:`int`, :py:class:`int`]"),
242+
(Tuple[str, ...], ":py:data:`~typing.Tuple`\\ \\[:py:class:`str`, :py:data:`...<Ellipsis>`]"),
243243
(Union, ":py:data:`~typing.Union`"),
244-
(Union[str, bool], ":py:data:`~typing.Union`\\[:py:class:`str`, :py:class:`bool`]"),
245-
(Union[str, bool, None], ":py:data:`~typing.Union`\\[:py:class:`str`, :py:class:`bool`, :py:obj:`None`]"),
246-
pytest.param(Union[str, Any], ":py:data:`~typing.Union`\\[:py:class:`str`, :py:data:`~typing.Any`]"),
247-
(Optional[str], ":py:data:`~typing.Optional`\\[:py:class:`str`]"),
248-
(Union[str, None], ":py:data:`~typing.Optional`\\[:py:class:`str`]"),
244+
(Union[str, bool], ":py:data:`~typing.Union`\\ \\[:py:class:`str`, :py:class:`bool`]"),
245+
(Union[str, bool, None], ":py:data:`~typing.Union`\\ \\[:py:class:`str`, :py:class:`bool`, :py:obj:`None`]"),
246+
pytest.param(Union[str, Any], ":py:data:`~typing.Union`\\ \\[:py:class:`str`, :py:data:`~typing.Any`]"),
247+
(Optional[str], ":py:data:`~typing.Optional`\\ \\[:py:class:`str`]"),
248+
(Union[str, None], ":py:data:`~typing.Optional`\\ \\[:py:class:`str`]"),
249249
(
250250
Optional[Union[str, bool]],
251-
":py:data:`~typing.Union`\\[:py:class:`str`, :py:class:`bool`, :py:obj:`None`]",
251+
":py:data:`~typing.Union`\\ \\[:py:class:`str`, :py:class:`bool`, :py:obj:`None`]",
252252
),
253253
(Callable, ":py:data:`~typing.Callable`"),
254-
(Callable[..., int], ":py:data:`~typing.Callable`\\[:py:data:`...<Ellipsis>`, :py:class:`int`]"),
255-
(Callable[[int], int], ":py:data:`~typing.Callable`\\[\\[:py:class:`int`], :py:class:`int`]"),
254+
(Callable[..., int], ":py:data:`~typing.Callable`\\ \\[:py:data:`...<Ellipsis>`, :py:class:`int`]"),
255+
(Callable[[int], int], ":py:data:`~typing.Callable`\\ \\[\\[:py:class:`int`], :py:class:`int`]"),
256256
(
257257
Callable[[int, str], bool],
258-
":py:data:`~typing.Callable`\\[\\[:py:class:`int`, :py:class:`str`], :py:class:`bool`]",
258+
":py:data:`~typing.Callable`\\ \\[\\[:py:class:`int`, :py:class:`str`], :py:class:`bool`]",
259259
),
260260
(
261261
Callable[[int, str], None],
262-
":py:data:`~typing.Callable`\\[\\[:py:class:`int`, :py:class:`str`], :py:obj:`None`]",
262+
":py:data:`~typing.Callable`\\ \\[\\[:py:class:`int`, :py:class:`str`], :py:obj:`None`]",
263263
),
264264
(
265265
Callable[[T], T],
266-
":py:data:`~typing.Callable`\\[\\[:py:class:`~typing.TypeVar`\\(``T``)],"
266+
":py:data:`~typing.Callable`\\ \\[\\[:py:class:`~typing.TypeVar`\\(``T``)],"
267267
" :py:class:`~typing.TypeVar`\\(``T``)]",
268268
),
269269
(
270270
AbcCallable[[int, str], bool], # type: ignore[valid-type,misc,type-arg]
271-
":py:class:`~collections.abc.Callable`\\[\\[:py:class:`int`, :py:class:`str`], :py:class:`bool`]",
271+
":py:class:`~collections.abc.Callable`\\ \\[\\[:py:class:`int`, :py:class:`str`], :py:class:`bool`]",
272272
),
273273
(Pattern, ":py:class:`~typing.Pattern`"),
274-
(Pattern[str], ":py:class:`~typing.Pattern`\\[:py:class:`str`]"),
274+
(Pattern[str], ":py:class:`~typing.Pattern`\\ \\[:py:class:`str`]"),
275275
(IO, ":py:class:`~typing.IO`"),
276-
(IO[str], ":py:class:`~typing.IO`\\[:py:class:`str`]"),
276+
(IO[str], ":py:class:`~typing.IO`\\ \\[:py:class:`str`]"),
277277
(Metaclass, ":py:class:`~%s.Metaclass`" % __name__),
278278
(A, ":py:class:`~%s.A`" % __name__),
279279
(B, ":py:class:`~%s.B`" % __name__),
280-
(B[int], ":py:class:`~%s.B`\\[:py:class:`int`]" % __name__),
280+
(B[int], ":py:class:`~%s.B`\\ \\[:py:class:`int`]" % __name__),
281281
(C, ":py:class:`~%s.C`" % __name__),
282282
(D, ":py:class:`~%s.D`" % __name__),
283283
(E, ":py:class:`~%s.E`" % __name__),
284-
(E[int], ":py:class:`~%s.E`\\[:py:class:`int`]" % __name__),
284+
(E[int], ":py:class:`~%s.E`\\ \\[:py:class:`int`]" % __name__),
285285
(W, f":py:{'class' if PY310_PLUS else 'func'}:`~typing.NewType`\\(``W``, :py:class:`str`)"),
286286
(T, ":py:class:`~typing.TypeVar`\\(``T``)"),
287287
(U_co, ":py:class:`~typing.TypeVar`\\(``U_co``, covariant=True)"),
@@ -306,17 +306,17 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t
306306
# Zero-length tuple remains
307307
(Tuple[()], ":py:data:`~typing.Tuple`"),
308308
# Internal single tuple with simple types is flattened in the output
309-
(Tuple[(int,)], ":py:data:`~typing.Tuple`\\[:py:class:`int`]"),
310-
(Tuple[(int, int)], ":py:data:`~typing.Tuple`\\[:py:class:`int`, :py:class:`int`]"),
309+
(Tuple[(int,)], ":py:data:`~typing.Tuple`\\ \\[:py:class:`int`]"),
310+
(Tuple[(int, int)], ":py:data:`~typing.Tuple`\\ \\[:py:class:`int`, :py:class:`int`]"),
311311
# Ellipsis in single tuple also gets flattened
312-
(Tuple[(int, ...)], ":py:data:`~typing.Tuple`\\[:py:class:`int`, :py:data:`...<Ellipsis>`]"),
312+
(Tuple[(int, ...)], ":py:data:`~typing.Tuple`\\ \\[:py:class:`int`, :py:data:`...<Ellipsis>`]"),
313313
(
314314
RecList,
315-
":py:data:`~typing.Union`\\[:py:class:`int`, :py:class:`~typing.List`\\[RecList]]",
315+
":py:data:`~typing.Union`\\ \\[:py:class:`int`, :py:class:`~typing.List`\\ \\[RecList]]",
316316
),
317317
(
318318
MutualRecA,
319-
":py:data:`~typing.Union`\\[:py:class:`bool`, :py:class:`~typing.List`\\[MutualRecB]]",
319+
":py:data:`~typing.Union`\\ \\[:py:class:`bool`, :py:class:`~typing.List`\\ \\[MutualRecB]]",
320320
),
321321
]
322322

@@ -327,39 +327,39 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t
327327
(
328328
nptyping.NDArray[nptyping.Shape["*"], nptyping.Float],
329329
(
330-
":py:class:`~nptyping.ndarray.NDArray`\\[:py:class:`~nptyping.base_meta_classes.Shape`\\[*], "
330+
":py:class:`~nptyping.ndarray.NDArray`\\ \\[:py:class:`~nptyping.base_meta_classes.Shape`\\ \\[*], "
331331
":py:class:`~numpy.float64`]"
332332
),
333333
),
334334
(
335335
nptyping.NDArray[nptyping.Shape["64"], nptyping.Float],
336336
(
337-
":py:class:`~nptyping.ndarray.NDArray`\\[:py:class:`~nptyping.base_meta_classes.Shape`\\[64],"
337+
":py:class:`~nptyping.ndarray.NDArray`\\ \\[:py:class:`~nptyping.base_meta_classes.Shape`\\ \\[64],"
338338
" :py:class:`~numpy.float64`]"
339339
),
340340
),
341341
(
342342
nptyping.NDArray[nptyping.Shape["*, *"], nptyping.Float],
343343
(
344-
":py:class:`~nptyping.ndarray.NDArray`\\[:py:class:`~nptyping.base_meta_classes.Shape`\\[*, "
344+
":py:class:`~nptyping.ndarray.NDArray`\\ \\[:py:class:`~nptyping.base_meta_classes.Shape`\\ \\[*, "
345345
"*], :py:class:`~numpy.float64`]"
346346
),
347347
),
348348
(
349349
nptyping.NDArray[nptyping.Shape["*, ..."], nptyping.Float],
350-
":py:class:`~nptyping.ndarray.NDArray`\\[:py:data:`~typing.Any`, :py:class:`~numpy.float64`]",
350+
":py:class:`~nptyping.ndarray.NDArray`\\ \\[:py:data:`~typing.Any`, :py:class:`~numpy.float64`]",
351351
),
352352
(
353353
nptyping.NDArray[nptyping.Shape["*, 3"], nptyping.Float],
354354
(
355-
":py:class:`~nptyping.ndarray.NDArray`\\[:py:class:`~nptyping.base_meta_classes.Shape`\\[*, 3"
355+
":py:class:`~nptyping.ndarray.NDArray`\\ \\[:py:class:`~nptyping.base_meta_classes.Shape`\\ \\[*, 3"
356356
"], :py:class:`~numpy.float64`]"
357357
),
358358
),
359359
(
360360
nptyping.NDArray[nptyping.Shape["3, ..."], nptyping.Float],
361361
(
362-
":py:class:`~nptyping.ndarray.NDArray`\\[:py:class:`~nptyping.base_meta_classes.Shape`\\[3, "
362+
":py:class:`~nptyping.ndarray.NDArray`\\ \\[:py:class:`~nptyping.base_meta_classes.Shape`\\ \\[3, "
363363
"...], :py:class:`~numpy.float64`]"
364364
),
365365
),
@@ -379,7 +379,7 @@ def test_format_annotation(inv: Inventory, annotation: Any, expected_result: str
379379
# subsequent tests
380380
expected_result_not_simplified = expected_result.replace(", ``None``", "")
381381
# encapsulate Union in typing.Optional
382-
expected_result_not_simplified = ":py:data:`~typing.Optional`\\[" + expected_result_not_simplified
382+
expected_result_not_simplified = ":py:data:`~typing.Optional`\\ \\[" + expected_result_not_simplified
383383
expected_result_not_simplified += "]"
384384
conf = create_autospec(Config, simplify_optional_unions=False, _annotation_globals=globals())
385385
assert format_annotation(annotation, conf) == expected_result_not_simplified
@@ -421,11 +421,11 @@ def test_format_annotation(inv: Inventory, annotation: Any, expected_result: str
421421
@pytest.mark.parametrize(
422422
("annotation", "params", "expected_result"),
423423
[
424-
("ClassVar", int, ":py:data:`~typing.ClassVar`\\[:py:class:`int`]"),
424+
("ClassVar", int, ":py:data:`~typing.ClassVar`\\ \\[:py:class:`int`]"),
425425
("NoReturn", None, ":py:data:`~typing.NoReturn`"),
426-
("Literal", ("a", 1), ":py:data:`~typing.Literal`\\[``'a'``, ``1``]"),
426+
("Literal", ("a", 1), ":py:data:`~typing.Literal`\\ \\[``'a'``, ``1``]"),
427427
("Type", None, ":py:class:`~typing.Type`"),
428-
("Type", (A,), f":py:class:`~typing.Type`\\[:py:class:`~{__name__}.A`]"),
428+
("Type", (A,), f":py:class:`~typing.Type`\\ \\[:py:class:`~{__name__}.A`]"),
429429
],
430430
)
431431
def test_format_annotation_both_libs(library: ModuleType, annotation: str, params: Any, expected_result: str) -> None:
@@ -524,16 +524,11 @@ class dummy_module.DataClass(x)
524524

525525
def maybe_fix_py310(expected_contents: str) -> str:
526526
if not PY310_PLUS:
527-
return expected_contents
527+
return expected_contents.replace('"', "")
528+
528529
for old, new in [
529-
("*bool** | **None*", '"Optional"["bool"]'),
530-
("*int** | **str** | **float*", '"int" | "str" | "float"'),
531-
("*str** | **None*", '"Optional"["str"]'),
532-
("(*bool*)", '("bool")'),
533-
("(*int*", '("int"'),
534-
(" str", ' "str"'),
535-
('"Optional"["str"]', '"Optional"["str"]'),
536-
('"Optional"["Callable"[["int", "bytes"], "int"]]', '"Optional"["Callable"[["int", "bytes"], "int"]]'),
530+
("bool | None", '"Optional"["bool"]'),
531+
("str | None", '"Optional"["str"]'),
537532
]:
538533
expected_contents = expected_contents.replace(old, new)
539534
return expected_contents
@@ -559,14 +554,14 @@ def test_sphinx_output_future_annotations(app: SphinxTestApp, status: StringIO)
559554
Method docstring.
560555
561556
Parameters:
562-
* **x** (*bool** | **None*) -- foo
557+
* **x** (bool | None) -- foo
563558
564-
* **y** (*int** | **str** | **float*) -- bar
559+
* **y** ("int" | "str" | "float") -- bar
565560
566-
* **z** (*str** | **None*) -- baz
561+
* **z** (str | None) -- baz
567562
568563
Return type:
569-
str
564+
"str"
570565
"""
571566
expected_contents = maybe_fix_py310(dedent(expected_contents))
572567
assert contents == expected_contents
@@ -625,7 +620,7 @@ def test_sphinx_output_defaults(
625620
("formatter_config_val", "expected"),
626621
[
627622
(None, ['("bool") -- foo', '("int") -- bar', '"str"']),
628-
(lambda ann, conf: "Test", ["(*Test*) -- foo", "(*Test*) -- bar", "Test"]), # noqa: ARG005
623+
(lambda ann, conf: "Test", ["(Test) -- foo", "(Test) -- bar", "Test"]), # noqa: ARG005
629624
("some string", Exception("needs to be callable or `None`")),
630625
],
631626
)

0 commit comments

Comments
 (0)