##// END OF EJS Templates
cleanup 3.8 compat
Matthias Bussonnier -
Show More
@@ -2909,8 +2909,7 b' class InteractiveShell(SingletonConfigurable):'
2909 return False
2909 return False
2910 return _should_be_async(cell)
2910 return _should_be_async(cell)
2911
2911
2912 @asyncio.coroutine
2912 async def run_cell_async(self, raw_cell: str, store_history=False, silent=False, shell_futures=True) -> ExecutionResult:
2913 def run_cell_async(self, raw_cell: str, store_history=False, silent=False, shell_futures=True) -> ExecutionResult:
2914 """Run a complete IPython cell asynchronously.
2913 """Run a complete IPython cell asynchronously.
2915
2914
2916 Parameters
2915 Parameters
@@ -3052,7 +3051,7 b' class InteractiveShell(SingletonConfigurable):'
3052 if _run_async:
3051 if _run_async:
3053 interactivity = 'async'
3052 interactivity = 'async'
3054
3053
3055 has_raised = yield from self.run_ast_nodes(code_ast.body, cell_name,
3054 has_raised = await self.run_ast_nodes(code_ast.body, cell_name,
3056 interactivity=interactivity, compiler=compiler, result=result)
3055 interactivity=interactivity, compiler=compiler, result=result)
3057
3056
3058 self.last_execution_succeeded = not has_raised
3057 self.last_execution_succeeded = not has_raised
@@ -3132,8 +3131,7 b' class InteractiveShell(SingletonConfigurable):'
3132 ast.fix_missing_locations(node)
3131 ast.fix_missing_locations(node)
3133 return node
3132 return node
3134
3133
3135 @asyncio.coroutine
3134 async def run_ast_nodes(self, nodelist:ListType[AST], cell_name:str, interactivity='last_expr',
3136 def run_ast_nodes(self, nodelist:ListType[AST], cell_name:str, interactivity='last_expr',
3137 compiler=compile, result=None):
3135 compiler=compile, result=None):
3138 """Run a sequence of AST nodes. The execution mode depends on the
3136 """Run a sequence of AST nodes. The execution mode depends on the
3139 interactivity parameter.
3137 interactivity parameter.
@@ -3218,7 +3216,7 b' class InteractiveShell(SingletonConfigurable):'
3218 async_wrapper_code = compiler(mod, cell_name, 'exec')
3216 async_wrapper_code = compiler(mod, cell_name, 'exec')
3219 exec(async_wrapper_code, self.user_global_ns, self.user_ns)
3217 exec(async_wrapper_code, self.user_global_ns, self.user_ns)
3220 async_code = removed_co_newlocals(self.user_ns.pop('async-def-wrapper')).__code__
3218 async_code = removed_co_newlocals(self.user_ns.pop('async-def-wrapper')).__code__
3221 if (yield from self.run_code(async_code, result, async_=True)):
3219 if (await self.run_code(async_code, result, async_=True)):
3222 return True
3220 return True
3223 else:
3221 else:
3224 if sys.version_info > (3, 8):
3222 if sys.version_info > (3, 8):
@@ -3245,7 +3243,7 b' class InteractiveShell(SingletonConfigurable):'
3245 with compiler.extra_flags(getattr(ast, 'PyCF_ALLOW_TOP_LEVEL_AWAIT', 0x0) if self.autoawait else 0x0):
3243 with compiler.extra_flags(getattr(ast, 'PyCF_ALLOW_TOP_LEVEL_AWAIT', 0x0) if self.autoawait else 0x0):
3246 code = compiler(mod, cell_name, mode)
3244 code = compiler(mod, cell_name, mode)
3247 asy = compare(code)
3245 asy = compare(code)
3248 if (yield from self.run_code(code, result, async_=asy)):
3246 if (await self.run_code(code, result, async_=asy)):
3249 return True
3247 return True
3250
3248
3251 # Flush softspace
3249 # Flush softspace
@@ -3284,8 +3282,7 b' class InteractiveShell(SingletonConfigurable):'
3284
3282
3285 return eval(code_obj, user_ns)
3283 return eval(code_obj, user_ns)
3286
3284
3287 @asyncio.coroutine
3285 async def run_code(self, code_obj, result=None, *, async_=False):
3288 def run_code(self, code_obj, result=None, *, async_=False):
3289 """Execute a code object.
3286 """Execute a code object.
3290
3287
3291 When an exception occurs, self.showtraceback() is called to display a
3288 When an exception occurs, self.showtraceback() is called to display a
@@ -3317,11 +3314,11 b' class InteractiveShell(SingletonConfigurable):'
3317 try:
3314 try:
3318 self.hooks.pre_run_code_hook()
3315 self.hooks.pre_run_code_hook()
3319 if async_ and sys.version_info < (3,8):
3316 if async_ and sys.version_info < (3,8):
3320 last_expr = (yield from self._async_exec(code_obj, self.user_ns))
3317 last_expr = (await self._async_exec(code_obj, self.user_ns))
3321 code = compile('last_expr', 'fake', "single")
3318 code = compile('last_expr', 'fake', "single")
3322 exec(code, {'last_expr': last_expr})
3319 exec(code, {'last_expr': last_expr})
3323 elif async_ :
3320 elif async_ :
3324 yield from eval(code_obj, self.user_global_ns, self.user_ns)
3321 await eval(code_obj, self.user_global_ns, self.user_ns)
3325 else:
3322 else:
3326 exec(code_obj, self.user_global_ns, self.user_ns)
3323 exec(code_obj, self.user_global_ns, self.user_ns)
3327 finally:
3324 finally:
General Comments 0
You need to be logged in to leave comments. Login now