Skip to content

Commit ffed88f

Browse files
authored
py39: fix mypyc complaints part 2 (#9562)
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 Co-authored-by: hauntsaninja <>
1 parent 08f207e commit ffed88f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

mypy/fastparse.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ def parse(source: Union[str, bytes],
169169
tree.path = fnam
170170
tree.is_stub = is_stub_file
171171
except SyntaxError as e:
172-
if sys.version_info < (3, 9) and e.filename == "<fstring>":
172+
# alias to please mypyc
173+
is_py38_or_earlier = sys.version_info < (3, 9)
174+
if is_py38_or_earlier and e.filename == "<fstring>":
173175
# In Python 3.8 and earlier, syntax errors in f-strings have lineno relative to the
174176
# start of the f-string. This would be misleading, as mypy will report the error as the
175177
# lineno within the file.
@@ -1210,9 +1212,11 @@ def visit_Attribute(self, n: Attribute) -> Union[MemberExpr, SuperExpr]:
12101212
def visit_Subscript(self, n: ast3.Subscript) -> IndexExpr:
12111213
e = IndexExpr(self.visit(n.value), self.visit(n.slice))
12121214
self.set_line(e, n)
1215+
# alias to please mypyc
1216+
is_py38_or_earlier = sys.version_info < (3, 9)
12131217
if (
12141218
isinstance(n.slice, ast3.Slice) or
1215-
(sys.version_info < (3, 9) and isinstance(n.slice, ast3.ExtSlice))
1219+
(is_py38_or_earlier and isinstance(n.slice, ast3.ExtSlice))
12161220
):
12171221
# Before Python 3.9, Slice has no line/column in the raw ast. To avoid incompatibility
12181222
# visit_Slice doesn't set_line, even in Python 3.9 on.
@@ -1258,12 +1262,12 @@ def visit_Slice(self, n: ast3.Slice) -> SliceExpr:
12581262
# ExtSlice(slice* dims)
12591263
def visit_ExtSlice(self, n: ast3.ExtSlice) -> TupleExpr:
12601264
# cast for mypyc's benefit on Python 3.9
1261-
return TupleExpr(self.translate_expr_list(cast(Any, n.dims)))
1265+
return TupleExpr(self.translate_expr_list(cast(Any, n).dims))
12621266

12631267
# Index(expr value)
12641268
def visit_Index(self, n: Index) -> Node:
12651269
# cast for mypyc's benefit on Python 3.9
1266-
return self.visit(cast(Any, n.value))
1270+
return self.visit(cast(Any, n).value)
12671271

12681272

12691273
class TypeConverter:

0 commit comments

Comments
 (0)