##// END OF EJS Templates
draft compat 3.8
Matthias Bussonnier -
Show More
@@ -35,6 +35,7 b' import hashlib'
35 import linecache
35 import linecache
36 import operator
36 import operator
37 import time
37 import time
38 from contextlib import contextmanager
38
39
39 #-----------------------------------------------------------------------------
40 #-----------------------------------------------------------------------------
40 # Constants
41 # Constants
@@ -134,6 +135,17 b' class CachingCompiler(codeop.Compile):'
134 linecache._ipython_cache[name] = entry
135 linecache._ipython_cache[name] = entry
135 return name
136 return name
136
137
138 @contextmanager
139 def extra_flags(self, flags):
140 old_flags = self.flags
141 self.flags = self.flags | flags
142 print('flags', old_flags ,'->', self.flags)
143 try:
144 yield
145 finally:
146 self.flags = old_flags
147
148
137 def check_linecache_ipython(*args):
149 def check_linecache_ipython(*args):
138 """Call linecache.checkcache() safely protecting our cached values.
150 """Call linecache.checkcache() safely protecting our cached values.
139 """
151 """
@@ -210,6 +210,8 b' def _ast_asyncify(cell:str, wrapper_name:str) -> ast.Module:'
210 """
210 """
211
211
212 from ast import Expr, Await, Return
212 from ast import Expr, Await, Return
213 if sys.version_info >= (3,8):
214 return ast.parse(cell)
213 tree = ast.parse(_asyncify(cell))
215 tree = ast.parse(_asyncify(cell))
214
216
215 function_def = tree.body[0]
217 function_def = tree.body[0]
@@ -3194,11 +3196,12 b' class InteractiveShell(SingletonConfigurable):'
3194 elif interactivity == 'all':
3196 elif interactivity == 'all':
3195 to_run_exec, to_run_interactive = [], nodelist
3197 to_run_exec, to_run_interactive = [], nodelist
3196 elif interactivity == 'async':
3198 elif interactivity == 'async':
3199 to_run_exec, to_run_interactive = [], nodelist
3197 _async = True
3200 _async = True
3198 else:
3201 else:
3199 raise ValueError("Interactivity was %r" % interactivity)
3202 raise ValueError("Interactivity was %r" % interactivity)
3200 try:
3203 try:
3201 if _async:
3204 if _async and sys.version_info < (3,8):
3202 # If interactivity is async the semantics of run_code are
3205 # If interactivity is async the semantics of run_code are
3203 # completely different Skip usual machinery.
3206 # completely different Skip usual machinery.
3204 mod = Module(nodelist, [])
3207 mod = Module(nodelist, [])
@@ -3215,9 +3218,11 b' class InteractiveShell(SingletonConfigurable):'
3215 return True
3218 return True
3216
3219
3217 for i, node in enumerate(to_run_interactive):
3220 for i, node in enumerate(to_run_interactive):
3221 print('B: interactive, async=', _async, nodelist)
3218 mod = ast.Interactive([node])
3222 mod = ast.Interactive([node])
3219 code = compiler(mod, cell_name, "single")
3223 with compiler.extra_flags(0x2000 if _async else 0x0):
3220 if (yield from self.run_code(code, result)):
3224 code = compiler(mod, cell_name, "single")
3225 if (yield from self.run_code(code, result, async_=_async)):
3221 return True
3226 return True
3222
3227
3223 # Flush softspace
3228 # Flush softspace
@@ -3288,10 +3293,12 b' class InteractiveShell(SingletonConfigurable):'
3288 try:
3293 try:
3289 try:
3294 try:
3290 self.hooks.pre_run_code_hook()
3295 self.hooks.pre_run_code_hook()
3291 if async_:
3296 if async_ and sys.version_info < (3,8):
3292 last_expr = (yield from self._async_exec(code_obj, self.user_ns))
3297 last_expr = (yield from self._async_exec(code_obj, self.user_ns))
3293 code = compile('last_expr', 'fake', "single")
3298 code = compile('last_expr', 'fake', "single")
3294 exec(code, {'last_expr': last_expr})
3299 exec(code, {'last_expr': last_expr})
3300 elif async_ :
3301 res = yield from eval(code_obj, self.user_ns)
3295 else:
3302 else:
3296 exec(code_obj, self.user_global_ns, self.user_ns)
3303 exec(code_obj, self.user_global_ns, self.user_ns)
3297 finally:
3304 finally:
General Comments 0
You need to be logged in to leave comments. Login now