Show More
@@ -139,7 +139,6 b' class CachingCompiler(codeop.Compile):' | |||||
139 | def extra_flags(self, flags): |
|
139 | def extra_flags(self, flags): | |
140 | old_flags = self.flags |
|
140 | old_flags = self.flags | |
141 | self.flags = self.flags | flags |
|
141 | self.flags = self.flags | flags | |
142 | print('flags', old_flags ,'->', self.flags) |
|
|||
143 | try: |
|
142 | try: | |
144 | yield |
|
143 | yield | |
145 | finally: |
|
144 | finally: |
@@ -3202,6 +3202,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
3202 | raise ValueError("Interactivity was %r" % interactivity) |
|
3202 | raise ValueError("Interactivity was %r" % interactivity) | |
3203 | try: |
|
3203 | try: | |
3204 | if _async and sys.version_info < (3,8): |
|
3204 | if _async and sys.version_info < (3,8): | |
|
3205 | raise ValueError | |||
3205 | # If interactivity is async the semantics of run_code are |
|
3206 | # If interactivity is async the semantics of run_code are | |
3206 | # completely different Skip usual machinery. |
|
3207 | # completely different Skip usual machinery. | |
3207 | mod = Module(nodelist, []) |
|
3208 | mod = Module(nodelist, []) | |
@@ -3211,18 +3212,26 b' class InteractiveShell(SingletonConfigurable):' | |||||
3211 | if (yield from self.run_code(async_code, result, async_=True)): |
|
3212 | if (yield from self.run_code(async_code, result, async_=True)): | |
3212 | return True |
|
3213 | return True | |
3213 | else: |
|
3214 | else: | |
|
3215 | def compare(code): | |||
|
3216 | import inspect | |||
|
3217 | is_async = (inspect.CO_COROUTINE & code.co_flags == inspect.CO_COROUTINE) | |||
|
3218 | print('async=', _async, 'autodetect=', is_async) | |||
|
3219 | return is_async | |||
3214 | for i, node in enumerate(to_run_exec): |
|
3220 | for i, node in enumerate(to_run_exec): | |
3215 | mod = Module([node], []) |
|
3221 | mod = Module([node], []) | |
3216 | code = compiler(mod, cell_name, "exec") |
|
3222 | code = compiler(mod, cell_name, "exec") | |
|
3223 | compare(code) | |||
3217 | if (yield from self.run_code(code, result)): |
|
3224 | if (yield from self.run_code(code, result)): | |
3218 | return True |
|
3225 | return True | |
3219 |
|
3226 | |||
3220 | for i, node in enumerate(to_run_interactive): |
|
3227 | for i, node in enumerate(to_run_interactive): | |
3221 | print('B: interactive, async=', _async, nodelist) |
|
3228 | print('B: interactive, async=', _async, nodelist) | |
3222 | mod = ast.Interactive([node]) |
|
3229 | mod = ast.Interactive([node]) | |
3223 |
with compiler.extra_flags( |
|
3230 | with compiler.extra_flags(ast.ast.PyCF_ALLOW_TOP_LEVEL_AWAIT if _async else 0x0): | |
3224 | code = compiler(mod, cell_name, "single") |
|
3231 | code = compiler(mod, cell_name, "single") | |
3225 | if (yield from self.run_code(code, result, async_=_async)): |
|
3232 | asy = compare(code) | |
|
3233 | ||||
|
3234 | if (yield from self.run_code(code, result, async_=asy)): | |||
3226 | return True |
|
3235 | return True | |
3227 |
|
3236 | |||
3228 | # Flush softspace |
|
3237 | # Flush softspace | |
@@ -3298,7 +3307,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
3298 | code = compile('last_expr', 'fake', "single") |
|
3307 | code = compile('last_expr', 'fake', "single") | |
3299 | exec(code, {'last_expr': last_expr}) |
|
3308 | exec(code, {'last_expr': last_expr}) | |
3300 | elif async_ : |
|
3309 | elif async_ : | |
3301 |
|
|
3310 | yield from eval(code_obj, self.user_global_ns, self.user_ns) | |
3302 | else: |
|
3311 | else: | |
3303 | exec(code_obj, self.user_global_ns, self.user_ns) |
|
3312 | exec(code_obj, self.user_global_ns, self.user_ns) | |
3304 | finally: |
|
3313 | finally: |
General Comments 0
You need to be logged in to leave comments.
Login now