diff --git a/mypy/fastparse.py b/mypy/fastparse.py index 0b72214100d8..3319cd648957 100644 --- a/mypy/fastparse.py +++ b/mypy/fastparse.py @@ -169,7 +169,9 @@ def parse(source: Union[str, bytes], tree.path = fnam tree.is_stub = is_stub_file except SyntaxError as e: - if sys.version_info < (3, 9) and e.filename == "": + # alias to please mypyc + is_py38_or_earlier = sys.version_info < (3, 9) + if is_py38_or_earlier and e.filename == "": # In Python 3.8 and earlier, syntax errors in f-strings have lineno relative to the # start of the f-string. This would be misleading, as mypy will report the error as the # lineno within the file. @@ -1210,9 +1212,11 @@ def visit_Attribute(self, n: Attribute) -> Union[MemberExpr, SuperExpr]: def visit_Subscript(self, n: ast3.Subscript) -> IndexExpr: e = IndexExpr(self.visit(n.value), self.visit(n.slice)) self.set_line(e, n) + # alias to please mypyc + is_py38_or_earlier = sys.version_info < (3, 9) if ( isinstance(n.slice, ast3.Slice) or - (sys.version_info < (3, 9) and isinstance(n.slice, ast3.ExtSlice)) + (is_py38_or_earlier and isinstance(n.slice, ast3.ExtSlice)) ): # Before Python 3.9, Slice has no line/column in the raw ast. To avoid incompatibility # visit_Slice doesn't set_line, even in Python 3.9 on. @@ -1258,12 +1262,12 @@ def visit_Slice(self, n: ast3.Slice) -> SliceExpr: # ExtSlice(slice* dims) def visit_ExtSlice(self, n: ast3.ExtSlice) -> TupleExpr: # cast for mypyc's benefit on Python 3.9 - return TupleExpr(self.translate_expr_list(cast(Any, n.dims))) + return TupleExpr(self.translate_expr_list(cast(Any, n).dims)) # Index(expr value) def visit_Index(self, n: Index) -> Node: # cast for mypyc's benefit on Python 3.9 - return self.visit(cast(Any, n.value)) + return self.visit(cast(Any, n).value) class TypeConverter: