3
3
from __future__ import annotations
4
4
5
5
import re
6
- import sys
7
6
import inspect
8
7
from io import StringIO
9
- from typing import (
10
- TYPE_CHECKING ,
11
- Any ,
12
- Union ,
13
- AnyStr ,
14
- NoReturn ,
15
- Optional ,
16
- cast ,
17
- get_origin ,
18
- )
8
+ from typing import TYPE_CHECKING , Any , AnyStr , NoReturn , cast , get_origin
19
9
from pathlib import Path
20
10
from operator import attrgetter
21
11
from collections .abc import Mapping , Callable
31
21
32
22
from sphinx .application import Sphinx
33
23
24
+ from scanpydoc .testing import MakeApp
25
+
34
26
class ProcessDoc (Protocol ): # noqa: D101
35
27
def __call__ ( # noqa: D102
36
28
self , fn : Callable [..., Any ], * , run_napoleon : bool = False
@@ -60,7 +52,7 @@ class Gen(Generic[T]): pass
60
52
61
53
62
54
@pytest .fixture
63
- def app (make_app_setup : Callable [..., Sphinx ] ) -> Sphinx :
55
+ def app (make_app_setup : MakeApp ) -> Sphinx :
64
56
return make_app_setup (
65
57
master_doc = "index" ,
66
58
extensions = [
@@ -256,8 +248,8 @@ def fn_test(m: object) -> None: # pragma: no cover
256
248
AnyStr ,
257
249
NoReturn ,
258
250
Callable [[int ], None ],
259
- Union [ int , str ] ,
260
- Union [ int , str , None ] ,
251
+ int | str ,
252
+ int | str | None ,
261
253
],
262
254
ids = lambda p : str (p ).replace ("typing." , "" ),
263
255
)
@@ -274,7 +266,6 @@ def test_typing_classes(app: Sphinx, annotation: type) -> None:
274
266
assert output is None or output .startswith (f":py:data:`typing.{ name } " )
275
267
276
268
277
- @pytest .mark .skipif (sys .version_info < (3 , 10 ), reason = "requires Python 3.10+" )
278
269
def test_union_type (app : Sphinx ) -> None :
279
270
union = eval ("int | str" ) # noqa: S307
280
271
assert typehints_formatter (union , app .config ) is None
@@ -389,15 +380,15 @@ class B:
389
380
("return_ann" , "foo_rendered" ),
390
381
[
391
382
pytest .param (tuple [str , int ], ":py:class:`str`" , id = "tuple" ),
392
- pytest .param (Optional [ tuple [str , int ]] , ":py:class:`str`" , id = "tuple | None" ),
383
+ pytest .param (tuple [str , int ] | None , ":py:class:`str`" , id = "tuple | None" ),
393
384
pytest .param (
394
385
tuple [Mapping [str , float ], int ],
395
386
r":py:class:`~collections.abc.Mapping`\ \["
396
387
":py:class:`str`, :py:class:`float`"
397
388
"]" ,
398
389
id = "complex" ,
399
390
),
400
- pytest .param (Optional [ int ] , None , id = "int | None" ),
391
+ pytest .param (int | None , None , id = "int | None" ),
401
392
],
402
393
)
403
394
def test_return_tuple (
@@ -472,14 +463,14 @@ def fn() -> tuple[int, str]: # pragma: no cover
472
463
assert res [2 ].startswith (":rtype: :sphinx_autodoc_typehints_type:" )
473
464
474
465
475
- def test_load_without_sat (make_app_setup : Callable [..., Sphinx ] ) -> None :
466
+ def test_load_without_sat (make_app_setup : MakeApp ) -> None :
476
467
make_app_setup (
477
468
master_doc = "index" ,
478
469
extensions = ["sphinx.ext.autodoc" , "scanpydoc.elegant_typehints" ],
479
470
)
480
471
481
472
482
- def test_load_error (make_app_setup : Callable [..., Sphinx ] ) -> None :
473
+ def test_load_error (make_app_setup : MakeApp ) -> None :
483
474
with pytest .raises (
484
475
RuntimeError ,
485
476
match = r"`scanpydoc.elegant_typehints` requires `sphinx.ext.autodoc`" ,
0 commit comments