##// END OF EJS Templates
more work
Matthias Bussonnier -
Show More
@@ -153,7 +153,8 b' def _should_be_async(cell: str) -> bool:'
153 try:
153 try:
154 # we can't limit ourself to ast.parse, as it __accepts__ to parse on
154 # we can't limit ourself to ast.parse, as it __accepts__ to parse on
155 # 3.7+, but just does not _compile_
155 # 3.7+, but just does not _compile_
156 code = compile(cell, "<>", "exec", flags=ast.PyCF_ALLOW_TOP_LEVEL_AWAIT)
156 # code = compile(cell, "<>", "exec", flags=getattr(ast,'PyCF_ALLOW_TOP_LEVEL_AWAIT', 0x0))
157 code = compile(cell, "<>", "exec")
157 return inspect.CO_COROUTINE & code.co_flags == inspect.CO_COROUTINE
158 return inspect.CO_COROUTINE & code.co_flags == inspect.CO_COROUTINE
158 except SyntaxError:
159 except SyntaxError:
159 #if sys.version_info > (3, 8):
160 #if sys.version_info > (3, 8):
@@ -3045,7 +3045,8 b' class InteractiveShell(SingletonConfigurable):'
3045 # Execute the user code
3045 # Execute the user code
3046 interactivity = "none" if silent else self.ast_node_interactivity
3046 interactivity = "none" if silent else self.ast_node_interactivity
3047 if _run_async:
3047 if _run_async:
3048 interactivity = 'async'
3048 print(interactivity)
3049 interactivity = 'last_expr'
3049
3050
3050 has_raised = yield from self.run_ast_nodes(code_ast.body, cell_name,
3051 has_raised = yield from self.run_ast_nodes(code_ast.body, cell_name,
3051 interactivity=interactivity, compiler=compiler, result=result)
3052 interactivity=interactivity, compiler=compiler, result=result)
@@ -3167,6 +3168,9 b' class InteractiveShell(SingletonConfigurable):'
3167 """
3168 """
3168 if not nodelist:
3169 if not nodelist:
3169 return
3170 return
3171 if interactivity == 'async':
3172 interactivify = 'last'
3173
3170 if interactivity == 'last_expr_or_assign':
3174 if interactivity == 'last_expr_or_assign':
3171 if isinstance(nodelist[-1], _assign_nodes):
3175 if isinstance(nodelist[-1], _assign_nodes):
3172 asg = nodelist[-1]
3176 asg = nodelist[-1]
@@ -3200,6 +3204,8 b' class InteractiveShell(SingletonConfigurable):'
3200 _async = True
3204 _async = True
3201 else:
3205 else:
3202 raise ValueError("Interactivity was %r" % interactivity)
3206 raise ValueError("Interactivity was %r" % interactivity)
3207
3208 print('interactivity:', interactivity)
3203 try:
3209 try:
3204 if _async and sys.version_info < (3,8):
3210 if _async and sys.version_info < (3,8):
3205 raise ValueError
3211 raise ValueError
@@ -3217,17 +3223,20 b' class InteractiveShell(SingletonConfigurable):'
3217 is_async = (inspect.CO_COROUTINE & code.co_flags == inspect.CO_COROUTINE)
3223 is_async = (inspect.CO_COROUTINE & code.co_flags == inspect.CO_COROUTINE)
3218 print('async=', _async, 'autodetect=', is_async)
3224 print('async=', _async, 'autodetect=', is_async)
3219 return is_async
3225 return is_async
3226
3227 # refactor that to just change the mod constructor.
3220 for i, node in enumerate(to_run_exec):
3228 for i, node in enumerate(to_run_exec):
3221 mod = Module([node], [])
3229 mod = Module([node], [])
3222 code = compiler(mod, cell_name, "exec")
3230 with compiler.extra_flags(getattr(ast, 'PyCF_ALLOW_TOP_LEVEL_AWAIT', 0x0) if self.autoawait else 0x0):
3223 compare(code)
3231 code = compiler(mod, cell_name, "exec")
3224 if (yield from self.run_code(code, result)):
3232 asy = compare(code)
3233 if (yield from self.run_code(code, result, async_=asy)):
3225 return True
3234 return True
3226
3235
3227 for i, node in enumerate(to_run_interactive):
3236 for i, node in enumerate(to_run_interactive):
3228 print('B: interactive, async=', _async, nodelist)
3237 print('B: interactive, async=', _async, nodelist)
3229 mod = ast.Interactive([node])
3238 mod = ast.Interactive([node])
3230 with compiler.extra_flags(ast.PyCF_ALLOW_TOP_LEVEL_AWAIT if self.autoawait else 0x0):
3239 with compiler.extra_flags(getattr(ast, 'PyCF_ALLOW_TOP_LEVEL_AWAIT', 0x0) if self.autoawait else 0x0):
3231 code = compiler(mod, cell_name, "single")
3240 code = compiler(mod, cell_name, "single")
3232 asy = compare(code)
3241 asy = compare(code)
3233
3242
General Comments 0
You need to be logged in to leave comments. Login now