Show More
@@ -10,7 +10,9 b' deprecated in 7.0.' | |||||
10 | # Copyright (c) IPython Development Team. |
|
10 | # Copyright (c) IPython Development Team. | |
11 | # Distributed under the terms of the Modified BSD License. |
|
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 | |||
14 | import re |
|
16 | import re | |
15 | import tokenize |
|
17 | import tokenize | |
16 | from typing import List, Tuple, Optional, Any |
|
18 | from typing import List, Tuple, Optional, Any | |
@@ -773,3 +775,20 b' def find_last_indent(lines):' | |||||
773 | if not m: |
|
775 | if not m: | |
774 | return 0 |
|
776 | return 0 | |
775 | return len(m.group(0).replace('\t', ' '*4)) |
|
777 | return len(m.group(0).replace('\t', ' '*4)) | |
|
778 | ||||
|
779 | ||||
|
780 | class MaybeAsyncCommandCompiler(CommandCompiler): | |||
|
781 | def __init__(self, extra_flags=0): | |||
|
782 | self.compiler = self._compiler | |||
|
783 | self.extra_flags = extra_flags | |||
|
784 | ||||
|
785 | def _compiler(self, source, filename, symbol, flags, feature): | |||
|
786 | flags |= self.extra_flags | |||
|
787 | return compile(source, filename, symbol, flags, feature) | |||
|
788 | ||||
|
789 | if (sys.version_info.major, sys.version_info.minor) >= (3, 8): | |||
|
790 | _extra_flags = ast.PyCF_ALLOW_TOP_LEVEL_AWAIT | |||
|
791 | else: | |||
|
792 | _extra_flags = ast.PyCF_ONLY_AST | |||
|
793 | ||||
|
794 | compile_command = MaybeAsyncCommandCompiler(extra_flags=_extra_flags) |
General Comments 0
You need to be logged in to leave comments.
Login now