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

Mypy ignores type annotation in assignment to square bracket target list #4340

Closed
elazarg opened this Issue Dec 11, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@elazarg
Contributor

elazarg commented Dec 11, 2017

from typing import Tuple, List
(x1, y1) = (1, 2)  # type: Tuple[str, int]  # E: Incompatible types in assignment (expression has type "int", variable has type "str")
[x2, y2] = (1, 2)  # type: Tuple[str, int]  # no error - bad
reveal_type(x2)  # E: Revealed type is 'builtins.int' - bad

Since the notation [x1, y1] is just another syntax for target list, the above notation should work. But even if they shouldn't, mypy should at least warn about mismatched notation.

IMHO mypy should not differentiate at all between the cases after parsing - there should be only TupleTypeTupleExpr for lvalues.

@gvanrossum

This comment has been minimized.

Member

gvanrossum commented Dec 11, 2017

Agreed. It looks as if in this case it ignored the second # type: annotation?

@elazarg

This comment has been minimized.

Contributor

elazarg commented Dec 11, 2017

Yes - you can put any valid type there, not only Tuple.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment