##// END OF EJS Templates
reformat with black
Matthias Bussonnier -
Show More
@@ -9,7 +9,6 b' be prevented as early return will not work.'
9 """
9 """
10
10
11
11
12
13 import ast
12 import ast
14 import sys
13 import sys
15 import inspect
14 import inspect
@@ -22,6 +21,7 b' def _asyncio_runner(coro):'
22 Handler for asyncio autoawait
21 Handler for asyncio autoawait
23 """
22 """
24 import asyncio
23 import asyncio
24
25 return asyncio.get_event_loop().run_until_complete(coro)
25 return asyncio.get_event_loop().run_until_complete(coro)
26
26
27
27
@@ -30,12 +30,14 b' def _curio_runner(coroutine):'
30 handler for curio autoawait
30 handler for curio autoawait
31 """
31 """
32 import curio
32 import curio
33
33 return curio.run(coroutine)
34 return curio.run(coroutine)
34
35
35
36
36 if sys.version_info > (3, 5):
37 if sys.version_info > (3, 5):
37 # nose refuses to avoid this file and async def is invalidsyntax
38 # nose refuses to avoid this file and async def is invalidsyntax
38 s = dedent('''
39 s = dedent(
40 '''
39 def _trio_runner(function):
41 def _trio_runner(function):
40 import trio
42 import trio
41 async def loc(coro):
43 async def loc(coro):
@@ -45,7 +47,8 b' if sys.version_info > (3, 5):'
45 """
47 """
46 return await coro
48 return await coro
47 return trio.run(loc, function)
49 return trio.run(loc, function)
48 ''')
50 '''
51 )
49 exec(s, globals(), locals())
52 exec(s, globals(), locals())
50
53
51
54
@@ -54,13 +57,15 b' def _asyncify(code: str) -> str:'
54
57
55 And setup a bit of context to run it later.
58 And setup a bit of context to run it later.
56 """
59 """
57 res = dedent("""
60 res = dedent(
61 """
58 async def __wrapper__():
62 async def __wrapper__():
59 try:
63 try:
60 {usercode}
64 {usercode}
61 finally:
65 finally:
62 locals()
66 locals()
63 """).format(usercode=indent(code, ' ' * 8)[8:])
67 """
68 ).format(usercode=indent(code, " " * 8)[8:])
64 return res
69 return res
65
70
66
71
@@ -79,7 +84,7 b' def _should_be_async(cell: str) -> bool:'
79 try:
84 try:
80 # we can't limit ourself to ast.parse, as it __accepts__ to parse on
85 # we can't limit ourself to ast.parse, as it __accepts__ to parse on
81 # 3.7+, but just does not _compile_
86 # 3.7+, but just does not _compile_
82 compile(cell, '<>', 'exec')
87 compile(cell, "<>", "exec")
83 return False
88 return False
84 except SyntaxError:
89 except SyntaxError:
85 try:
90 try:
General Comments 0
You need to be logged in to leave comments. Login now