Show More
@@ -10,7 +10,9 b' deprecated in 7.0.' | |||
|
10 | 10 | # Copyright (c) IPython Development Team. |
|
11 | 11 | # Distributed under the terms of the Modified BSD License. |
|
12 | 12 | |
|
13 | from codeop import compile_command | |
|
13 | import ast | |
|
14 | import sys | |
|
15 | from codeop import CommandCompiler, Compile | |
|
14 | 16 | import re |
|
15 | 17 | import tokenize |
|
16 | 18 | from typing import List, Tuple, Union |
@@ -724,3 +726,25 b' def find_last_indent(lines):' | |||
|
724 | 726 | if not m: |
|
725 | 727 | return 0 |
|
726 | 728 | return len(m.group(0).replace('\t', ' '*4)) |
|
729 | ||
|
730 | ||
|
731 | class MaybeAsyncCompile(Compile): | |
|
732 | def __init__(self, extra_flags=0): | |
|
733 | super().__init__() | |
|
734 | self.flags |= extra_flags | |
|
735 | ||
|
736 | def __call__(self, *args, **kwds): | |
|
737 | return compile(*args, **kwds) | |
|
738 | ||
|
739 | ||
|
740 | class MaybeAsyncCommandCompiler(CommandCompiler): | |
|
741 | def __init__(self, extra_flags=0): | |
|
742 | self.compiler = MaybeAsyncCompile(extra_flags=extra_flags) | |
|
743 | ||
|
744 | ||
|
745 | if (sys.version_info.major, sys.version_info.minor) >= (3, 8): | |
|
746 | _extra_flags = ast.PyCF_ALLOW_TOP_LEVEL_AWAIT | |
|
747 | else: | |
|
748 | _extra_flags = ast.PyCF_ONLY_AST | |
|
749 | ||
|
750 | compile_command = MaybeAsyncCommandCompiler(extra_flags=_extra_flags) |
General Comments 0
You need to be logged in to leave comments.
Login now