Skip to content

py39: fix mypyc complaints part 2 #9562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "<fstring>":
# alias to please mypyc
is_py38_or_earlier = sys.version_info < (3, 9)
if is_py38_or_earlier and e.filename == "<fstring>":
# 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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down