KEMBAR78
Mypy ignores type annotation in assignment to square bracket target list · Issue #4340 · python/mypy · GitHub
Skip to content

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

@elazarg

Description

@elazarg
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions