13
13
__all__ = ('new_event_loop' , 'install' , 'EventLoopPolicy' )
14
14
15
15
16
+ _T = _typing .TypeVar ("_T" )
17
+
18
+
16
19
class Loop (__BaseLoop , __asyncio .AbstractEventLoop ): # type: ignore[misc]
17
20
pass
18
21
@@ -34,10 +37,25 @@ def install() -> None:
34
37
__asyncio .set_event_loop_policy (EventLoopPolicy ())
35
38
36
39
37
- def run (main , * , loop_factory = new_event_loop , debug = None , ** run_kwargs ):
40
+ @_typing .overload
41
+ def run (
42
+ main : _typing .Coroutine [_typing .Any , _typing .Any , _T ],
43
+ * ,
44
+ debug : _typing .Optional [bool ] = ...,
45
+ loop_factory : _typing .Optional [_typing .Callable [[], Loop ]] = ...,
46
+ ) -> _T : ...
47
+
48
+
49
+ def run (
50
+ main : _typing .Coroutine [_typing .Any , _typing .Any , _T ],
51
+ * ,
52
+ loop_factory : _typing .Optional [_typing .Callable [[], Loop ]] = new_event_loop ,
53
+ debug : _typing .Optional [bool ]= None ,
54
+ ** run_kwargs : object
55
+ ) -> _T :
38
56
"""The preferred way of running a coroutine with uvloop."""
39
57
40
- async def wrapper ():
58
+ async def wrapper () -> _T :
41
59
# If `loop_factory` is provided we want it to return
42
60
# either uvloop.Loop or a subtype of it, assuming the user
43
61
# is using `uvloop.run()` intentionally.
@@ -96,7 +114,7 @@ async def wrapper():
96
114
)
97
115
98
116
99
- def _cancel_all_tasks (loop ) :
117
+ def _cancel_all_tasks (loop : __asyncio . AbstractEventLoop ) -> None :
100
118
# Copied from python/cpython
101
119
102
120
to_cancel = __asyncio .all_tasks (loop )
0 commit comments