|
25 | 25 | from mypy.errors import Errors
|
26 | 26 |
|
27 | 27 | try:
|
28 |
| - from typed_ast import ast27 |
29 | 28 | from typed_ast import ast35
|
30 |
| - from typed_ast import conversions |
31 | 29 | except ImportError:
|
32 | 30 | if sys.version_info.minor > 2:
|
33 | 31 | print('You must install the typed_ast package before you can run mypy'
|
@@ -59,11 +57,8 @@ def parse(source: Union[str, bytes], fnam: str = None, errors: Errors = None,
|
59 | 57 | """
|
60 | 58 | is_stub_file = bool(fnam) and fnam.endswith('.pyi')
|
61 | 59 | try:
|
62 |
| - if pyversion[0] >= 3 or is_stub_file: |
63 |
| - ast = ast35.parse(source, fnam, 'exec') |
64 |
| - else: |
65 |
| - ast2 = ast27.parse(source, fnam, 'exec') |
66 |
| - ast = conversions.py2to3(ast2) |
| 60 | + assert pyversion[0] >= 3 or is_stub_file |
| 61 | + ast = ast35.parse(source, fnam, 'exec') |
67 | 62 |
|
68 | 63 | tree = ASTConverter(pyversion=pyversion,
|
69 | 64 | is_stub=is_stub_file,
|
@@ -802,6 +797,12 @@ class TypeConverter(ast35.NodeTransformer):
|
802 | 797 | def __init__(self, line: int = -1) -> None:
|
803 | 798 | self.line = line
|
804 | 799 |
|
| 800 | + def visit_raw_str(self, s: str) -> Type: |
| 801 | + # An escape hatch that allows the AST walker in fastparse2 to |
| 802 | + # directly hook into the Python 3.5 type converter in some cases |
| 803 | + # without needing to create an intermediary `ast35.Str` object. |
| 804 | + return parse_type_comment(s.strip(), line=self.line) |
| 805 | + |
805 | 806 | def generic_visit(self, node: ast35.AST) -> None:
|
806 | 807 | raise TypeCommentParseError(TYPE_COMMENT_AST_ERROR, self.line)
|
807 | 808 |
|
|
0 commit comments