Skip to content

Mypy errors with variable reuse with different types #1174

@timabbott

Description

@timabbott
from typing import * class Test(object): x = 1 y = 2 for sub in [(1, 2)]: pass subs = {} # type: Dict[Tuple[int, int], Test] for sub in [Test()]: subs[(sub.x, sub.y)] = sub 

gives

/home/tabbott/foo.py:11: error: Incompatible types in assignment (expression has type "Test", variable has type "Tuple[int, int]") /home/tabbott/foo.py:12: error: Tuple[int, ...] has no attribute "x" /home/tabbott/foo.py:12: error: Tuple[int, ...] has no attribute "y" /home/tabbott/foo.py:12: error: Incompatible types in assignment 

Arguably this is not perfect code, but probably this shouldn't be a mypy error?

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions