Show More
@@ -12,7 +12,7 b' deprecated in 7.0.' | |||||
12 |
|
12 | |||
13 | import ast |
|
13 | import ast | |
14 | import sys |
|
14 | import sys | |
15 | from codeop import CommandCompiler |
|
15 | from codeop import CommandCompiler, Compile | |
16 | import re |
|
16 | import re | |
17 | import tokenize |
|
17 | import tokenize | |
18 | from typing import List, Tuple, Optional, Any |
|
18 | from typing import List, Tuple, Optional, Any | |
@@ -777,14 +777,18 b' def find_last_indent(lines):' | |||||
777 | return len(m.group(0).replace('\t', ' '*4)) |
|
777 | return len(m.group(0).replace('\t', ' '*4)) | |
778 |
|
778 | |||
779 |
|
779 | |||
|
780 | class MaybeAsyncCompile(Compile): | |||
|
781 | def __init__(self, extra_flags=0): | |||
|
782 | super().__init__() | |||
|
783 | self.flags |= extra_flags | |||
|
784 | ||||
|
785 | __call__ = compile | |||
|
786 | ||||
|
787 | ||||
780 | class MaybeAsyncCommandCompiler(CommandCompiler): |
|
788 | class MaybeAsyncCommandCompiler(CommandCompiler): | |
781 | def __init__(self, extra_flags=0): |
|
789 | def __init__(self, extra_flags=0): | |
782 |
self.compiler = |
|
790 | self.compiler = MaybeAsyncCompile(extra_flags=extra_flags) | |
783 | self.extra_flags = extra_flags |
|
|||
784 |
|
791 | |||
785 | def _compiler(self, source, filename, symbol, flags, feature): |
|
|||
786 | flags |= self.extra_flags |
|
|||
787 | return compile(source, filename, symbol, flags, feature) |
|
|||
788 |
|
792 | |||
789 | if (sys.version_info.major, sys.version_info.minor) >= (3, 8): |
|
793 | if (sys.version_info.major, sys.version_info.minor) >= (3, 8): | |
790 | _extra_flags = ast.PyCF_ALLOW_TOP_LEVEL_AWAIT |
|
794 | _extra_flags = ast.PyCF_ALLOW_TOP_LEVEL_AWAIT |
General Comments 0
You need to be logged in to leave comments.
Login now