Skip to content

Fix typechecking on Python 3.8 #7953

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
Nov 14, 2019
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
9 changes: 6 additions & 3 deletions mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,16 @@ def set_line(self, node: N, n: Union[ast3.expr, ast3.stmt]) -> N:
node.end_line = getattr(n, "end_lineno", None) if isinstance(n, ast3.expr) else None
return node

def translate_expr_list(self, l: Sequence[AST]) -> List[Expression]:
res = [] # type: List[Expression]
def translate_opt_expr_list(self, l: Sequence[Optional[AST]]) -> List[Optional[Expression]]:
res = [] # type: List[Optional[Expression]]
for e in l:
exp = self.visit(e)
res.append(exp)
return res

def translate_expr_list(self, l: Sequence[AST]) -> List[Expression]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can use an overload instead?

@overload
def translate_expr_list(l: Sequence[AST]) -> List[Expression]: ...
@overload
def translate_expr_list(l: Sequence[Optional[AST]]) -> List[Optional[Expression]]: ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that first and it complained that they overlapped

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I think I remember having similar troubles with get_proper_types(). @Michael0x2a is this actually unsafe or maybe we can relax this somehow (I mean invariant generics in return types)?

return cast(List[Expression], self.translate_opt_expr_list(l))

def get_lineno(self, node: Union[ast3.expr, ast3.stmt]) -> int:
if (isinstance(node, (ast3.AsyncFunctionDef, ast3.ClassDef, ast3.FunctionDef))
and node.decorator_list):
Expand Down Expand Up @@ -988,7 +991,7 @@ def visit_IfExp(self, n: ast3.IfExp) -> ConditionalExpr:

# Dict(expr* keys, expr* values)
def visit_Dict(self, n: ast3.Dict) -> DictExpr:
e = DictExpr(list(zip(self.translate_expr_list(n.keys),
e = DictExpr(list(zip(self.translate_opt_expr_list(n.keys),
self.translate_expr_list(n.values))))
return self.set_line(e, n)

Expand Down