From 81818b23b5d53f31caf3515d6f0b54e3c018d790 Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Thu, 8 Oct 2020 13:00:20 -0700 Subject: [PATCH] py39: fix mypyc complaints part 2 Necessary because I previously didn't actually fix mypyc's complaint + mypyc has more complaints. The sys.version_info aliasing works around us hitting https://github.com/python/mypy/blob/08f207ef4a09f56d710d63775771ae921c41d4bc/mypyc/irbuild/expression.py#L44 --- mypy/fastparse.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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: