File tree Expand file tree Collapse file tree 1 file changed +11
-14
lines changed Expand file tree Collapse file tree 1 file changed +11
-14
lines changed Original file line number Diff line number Diff line change 11import ast
22import sys
3+ import types
34from collections import namedtuple
45from functools import partial
56from typing import Dict , Optional
67
78from astroid .const import PY38_PLUS , Context
89
9- try :
10- import typed_ast .ast3 as _ast_py3
11- except ImportError :
12- _ast_py3 = None
13-
14-
15- if PY38_PLUS :
10+ if sys .version_info >= (3 , 8 ):
1611 # On Python 3.8, typed_ast was merged back into `ast`
17- _ast_py3 = ast
18-
12+ _ast_py3 : Optional [types .ModuleType ] = ast
13+ else :
14+ try :
15+ import typed_ast .ast3 as _ast_py3
16+ except ImportError :
17+ _ast_py3 = None
1918
2019FunctionType = namedtuple ("FunctionType" , ["argtypes" , "returns" ])
2120
@@ -51,16 +50,14 @@ def parse_function_type_comment(type_comment: str) -> Optional[FunctionType]:
5150 if _ast_py3 is None :
5251 return None
5352
54- func_type = _ast_py3 .parse (type_comment , "<type_comment>" , "func_type" )
53+ func_type = _ast_py3 .parse (type_comment , "<type_comment>" , "func_type" ) # type: ignore[attr-defined]
5554 return FunctionType (argtypes = func_type .argtypes , returns = func_type .returns )
5655
5756
5857def get_parser_module (type_comments = True ) -> ParserModule :
59- if not type_comments :
60- parser_module = ast
61- else :
58+ parser_module = ast
59+ if type_comments and _ast_py3 :
6260 parser_module = _ast_py3
63- parser_module = parser_module or ast
6461
6562 unary_op_classes = _unary_operators_from_module (parser_module )
6663 cmp_op_classes = _compare_operators_from_module (parser_module )
You can’t perform that action at this time.
0 commit comments