|
15 | 15 | Callable, |
16 | 16 | Dict, |
17 | 17 | Generic, |
| 18 | + List, |
18 | 19 | Mapping, |
19 | 20 | Match, |
20 | 21 | NewType, |
|
55 | 56 | S = TypeVar("S", bound="miss") # type: ignore # miss not defined on purpose # noqa: F821 |
56 | 57 | W = NewType("W", str) |
57 | 58 |
|
| 59 | +# Mypy does not support recursive type aliases, but |
| 60 | +# other type checkers do. |
| 61 | +RecList = Union[int, List["RecList"]] # type: ignore |
| 62 | +MutualRecA = Union[bool, List["MutualRecB"]] # type: ignore |
| 63 | +MutualRecB = Union[str, List["MutualRecA"]] # type: ignore |
| 64 | + |
58 | 65 |
|
59 | 66 | class A: |
60 | 67 | def get_type(self) -> type: |
@@ -228,7 +235,7 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t |
228 | 235 | (V, ":py:class:`~typing.TypeVar`\\(``V``, contravariant=True)"), |
229 | 236 | (X, ":py:class:`~typing.TypeVar`\\(``X``, :py:class:`str`, :py:class:`int`)"), |
230 | 237 | (Y, ":py:class:`~typing.TypeVar`\\(``Y``, bound= :py:class:`str`)"), |
231 | | - (Z, ":py:class:`~typing.TypeVar`\\(``Z``, bound= :py:class:`~test_sphinx_autodoc_typehints.A`)"), |
| 238 | + (Z, ":py:class:`~typing.TypeVar`\\(``Z``, bound= A)"), |
232 | 239 | (S, ":py:class:`~typing.TypeVar`\\(``S``, bound= miss)"), |
233 | 240 | # ## These test for correct internal tuple rendering, even if not all are valid Tuple types |
234 | 241 | # Zero-length tuple remains |
@@ -279,6 +286,14 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t |
279 | 286 | "...], :py:class:`~numpy.float64`]" |
280 | 287 | ), |
281 | 288 | ), |
| 289 | + ( |
| 290 | + RecList, |
| 291 | + (":py:data:`~typing.Union`\\[:py:class:`int`, :py:class:`~typing.List`\\[RecList]]"), |
| 292 | + ), |
| 293 | + ( |
| 294 | + MutualRecA, |
| 295 | + (":py:data:`~typing.Union`\\[:py:class:`bool`, :py:class:`~typing.List`\\[MutualRecB]]"), |
| 296 | + ), |
282 | 297 | ], |
283 | 298 | ) |
284 | 299 | def test_format_annotation(inv: Inventory, annotation: Any, expected_result: str) -> None: |
|
0 commit comments