66from inspect import isclass
77from pathlib import Path
88from 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+ )
1019
1120import pytest
1221
1322if TYPE_CHECKING :
23+ from collections .abc import AsyncGenerator
1424 from io import StringIO
1525 from mailbox import Mailbox
1626 from types import CodeType , ModuleType
2131W = NewType ("W" , str )
2232
2333
24- def expected (expected : str ) -> Callable [[T ], T ]:
34+ def expected (expected : str , ** options : dict [ str , Any ] ) -> Callable [[T ], T ]:
2535 def dec (val : T ) -> T :
2636 val .EXPECTED = expected
37+ val .OPTIONS = options
2738 return val
2839
2940 return dec
@@ -1234,6 +1245,31 @@ def has_newtype(param: W) -> W:
12341245LT_PY310 = sys .version_info < (3 , 10 )
12351246
12361247
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+
12371273@pytest .mark .parametrize ("val" , [x for x in globals ().values () if hasattr (x , "EXPECTED" )])
12381274@pytest .mark .sphinx ("text" , testroot = "integration" )
12391275def test_integration (
@@ -1251,6 +1287,7 @@ def test_integration(
12511287 template = AUTO_FUNCTION
12521288
12531289 (Path (app .srcdir ) / "index.rst" ).write_text (template .format (val .__name__ ))
1290+ app .config .__dict__ .update (val .OPTIONS )
12541291 monkeypatch .setitem (sys .modules , "mod" , sys .modules [__name__ ])
12551292 app .build ()
12561293 assert "build succeeded" in status .getvalue () # Build succeeded
0 commit comments