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