6
6
from inspect import isclass
7
7
from pathlib import Path
8
8
from textwrap import dedent , indent
9
- from typing import TYPE_CHECKING , Any , Callable , NewType , Optional , TypeVar , Union , overload # no type comments
9
+ from typing import ( # no type comments
10
+ TYPE_CHECKING ,
11
+ Any ,
12
+ Callable ,
13
+ NewType ,
14
+ Optional ,
15
+ TypeVar ,
16
+ Union ,
17
+ overload ,
18
+ )
10
19
11
20
import pytest
12
21
13
22
if TYPE_CHECKING :
23
+ from collections .abc import AsyncGenerator
14
24
from io import StringIO
15
25
from mailbox import Mailbox
16
26
from types import CodeType , ModuleType
21
31
W = NewType ("W" , str )
22
32
23
33
24
- def expected (expected : str ) -> Callable [[T ], T ]:
34
+ def expected (expected : str , ** options : dict [ str , Any ] ) -> Callable [[T ], T ]:
25
35
def dec (val : T ) -> T :
26
36
val .EXPECTED = expected
37
+ val .OPTIONS = options
27
38
return val
28
39
29
40
return dec
@@ -1234,6 +1245,31 @@ def has_newtype(param: W) -> W:
1234
1245
LT_PY310 = sys .version_info < (3 , 10 )
1235
1246
1236
1247
1248
+ @expected (
1249
+ """
1250
+ mod.typehints_use_signature(a: AsyncGenerator) -> AsyncGenerator
1251
+
1252
+ Do something.
1253
+
1254
+ Parameters:
1255
+ **a** ("AsyncGenerator") -- blah
1256
+
1257
+ Return type:
1258
+ "AsyncGenerator"
1259
+
1260
+ """ ,
1261
+ typehints_use_signature = True ,
1262
+ typehints_use_signature_return = True ,
1263
+ )
1264
+ def typehints_use_signature (a : AsyncGenerator ) -> AsyncGenerator :
1265
+ """Do something.
1266
+
1267
+ Args:
1268
+ a: blah
1269
+ """
1270
+ return a
1271
+
1272
+
1237
1273
@pytest .mark .parametrize ("val" , [x for x in globals ().values () if hasattr (x , "EXPECTED" )])
1238
1274
@pytest .mark .sphinx ("text" , testroot = "integration" )
1239
1275
def test_integration (
@@ -1251,6 +1287,7 @@ def test_integration(
1251
1287
template = AUTO_FUNCTION
1252
1288
1253
1289
(Path (app .srcdir ) / "index.rst" ).write_text (template .format (val .__name__ ))
1290
+ app .config .__dict__ .update (val .OPTIONS )
1254
1291
monkeypatch .setitem (sys .modules , "mod" , sys .modules [__name__ ])
1255
1292
app .build ()
1256
1293
assert "build succeeded" in status .getvalue () # Build succeeded
0 commit comments