88import trio_asyncio
99from contextvars import ContextVar
1010
11- from .util import run_aio_generator , run_aio_future , run_trio_generator
12-
13- current_loop = ContextVar ('trio_aio_loop' , default = None )
14- current_policy = ContextVar ('trio_aio_policy' , default = None )
11+ from ._deprecate import deprecated_alias
12+ from ._util import run_aio_generator , run_aio_future , run_trio_generator
13+ from ._loop import current_loop , current_policy
1514
1615# import logging
1716# logger = logging.getLogger(__name__)
1817
1918from functools import wraps , partial
2019
21- __all__ = [
22- 'trio2aio' , 'aio2trio' , 'aio_as_trio' , 'trio_as_aio' , 'allow_asyncio' , 'current_loop' ,
23- 'current_policy' , 'asyncio_as_trio' , 'trio_as_asyncio'
24- ]
25-
26-
27- def trio2aio (proc ):
28- """Call asyncio code from Trio.
29-
30- Deprecated: Use aio_as_trio() instead.
31-
32- """
33- warnings .warn ("Use 'aio_as_trio(proc)' instead'" , DeprecationWarning )
34-
35- return aio_as_trio (proc )
36-
3720
3821async def _call_defer (proc , * args , ** kwargs ):
3922 return await proc (* args , ** kwargs )
@@ -210,30 +193,6 @@ def trio_as_aio(proc, *, loop=None):
210193trio_as_asyncio = trio_as_aio
211194
212195
213- def aio2trio (proc ):
214- """Call asyncio code from Trio.
215-
216- Deprecated: Use aio_as_trio() instead.
217-
218- """
219- warnings .warn ("Use 'trio_as_aio(proc)' instead'" , DeprecationWarning )
220-
221- return trio_as_aio (proc )
222-
223-
224- def aio2trio_task (proc ):
225- warnings .warn ("Use loop.run_trio_task() instead" , DeprecationWarning )
226-
227- @wraps (proc )
228- async def call (* args , ** kwargs ):
229- proc_ = proc
230- if kwargs :
231- proc_ = partial (proc_ , ** kwargs )
232- trio_asyncio .run_trio_task (proc_ , * args )
233-
234- return call
235-
236-
237196@types .coroutine
238197def _allow_asyncio (fn , * args ):
239198 shim = trio_asyncio .base ._shim_running
@@ -261,6 +220,8 @@ def _allow_asyncio(fn, *args):
261220 p , a = coro .send , next_send
262221
263222
223+ _shim_running = ContextVar ("shim_running" , default = False )
224+
264225async def allow_asyncio (fn , * args ):
265226 """
266227 This wrapper allows you to indiscrimnately mix :mod:`trio` and
@@ -287,11 +248,15 @@ async def main():
287248
288249 This function must be called from :mod:`trio` context.
289250 """
290- shim = trio_asyncio . base . _shim_running
251+ shim = _shim_running
291252 if shim .get (): # nested call: skip
292253 return await fn (* args )
293254 token = shim .set (True )
294255 try :
295256 return await _allow_asyncio (fn , * args )
296257 finally :
297258 shim .reset (token )
259+
260+
261+ trio2aio = deprecated_alias ("trio_asyncio.trio2aio" , aio_as_trio , "0.10.0" , issue = 38 )
262+ aio2trio = deprecated_alias ("trio_asyncio.aio2trio" , trio_as_aio , "0.10.0" , issue = 38 )
0 commit comments