diff --git a/IPython/core/async_helpers.py b/IPython/core/async_helpers.py index 46d2147..13de7b0 100644 --- a/IPython/core/async_helpers.py +++ b/IPython/core/async_helpers.py @@ -13,6 +13,7 @@ Python semantics. import ast import sys +import inspect from textwrap import dedent, indent @@ -98,6 +99,8 @@ class _AsyncSyntaxErrorVisitor(ast.NodeVisitor): is erroneously allowed (e.g. yield or return at the top level) """ def __init__(self): + if sys.version_info >= (3,8): + raise ValueError('DEPRECATED in Python 3.8+') self.depth = 0 super().__init__() @@ -150,9 +153,11 @@ def _should_be_async(cell: str) -> bool: try: # we can't limit ourself to ast.parse, as it __accepts__ to parse on # 3.7+, but just does not _compile_ - compile(cell, "<>", "exec") - return False + code = compile(cell, "<>", "exec", flags=ast.PyCF_ALLOW_TOP_LEVEL_AWAIT) + return inspect.CO_COROUTINE & code.co_flags == inspect.CO_COROUTINE except SyntaxError: + #if sys.version_info > (3, 8): + # raise try: parse_tree = _async_parse_cell(cell)