6
6
import asyncio
7
7
import sys
8
8
import inspect
9
+ from typing import Callable , Awaitable , Any , Union
9
10
10
11
11
- def check_ipython ():
12
+ def check_ipython () -> None :
12
13
# original from vaex/asyncio.py
13
14
IPython = sys .modules .get ('IPython' )
14
15
if IPython :
15
- IPython_version = tuple (map (int , IPython .__version__ .split ('.' )))
16
+ IPython_version = tuple (map (int , IPython .__version__ .split ('.' ))) # type: ignore
16
17
if IPython_version < (7 , 0 , 0 ):
17
- raise RuntimeError (f'You are using IPython { IPython .__version__ } while we require'
18
+ raise RuntimeError (f'You are using IPython { IPython .__version__ } while we require' # type: ignore
18
19
'7.0.0+, please update IPython' )
19
20
20
21
21
- def check_patch_tornado ():
22
+ def check_patch_tornado () -> None :
22
23
"""If tornado is imported, add the patched asyncio.Future to its tuple of acceptable Futures"""
23
24
# original from vaex/asyncio.py
24
25
if 'tornado' in sys .modules :
25
26
import tornado .concurrent
26
27
if asyncio .Future not in tornado .concurrent .FUTURES :
27
- tornado .concurrent .FUTURES = tornado .concurrent .FUTURES + (asyncio .Future , )
28
+ tornado .concurrent .FUTURES = tornado .concurrent .FUTURES + (asyncio .Future , ) # type: ignore
28
29
29
30
30
- def just_run (coro ) :
31
+ def just_run (coro : Awaitable ) -> Any :
31
32
"""Make the coroutine run, even if there is an event loop running (using nest_asyncio)"""
32
33
# original from vaex/asyncio.py
33
34
loop = asyncio ._get_running_loop ()
@@ -51,7 +52,7 @@ def just_run(coro):
51
52
return loop .run_until_complete (coro )
52
53
53
54
54
- def run_sync (coro ) :
55
+ def run_sync (coro : Callable ) -> Callable :
55
56
"""Runs a coroutine and blocks until it has executed.
56
57
57
58
An event loop is created if no one already exists. If an event loop is
@@ -74,7 +75,7 @@ def wrapped(*args, **kwargs):
74
75
return wrapped
75
76
76
77
77
- async def ensure_async (obj ) :
78
+ async def ensure_async (obj : Union [ Awaitable , Any ]) -> Any :
78
79
"""Convert a non-awaitable object to a coroutine if needed,
79
80
and await it if it was not already awaited.
80
81
"""
0 commit comments