Python 3.7.2, mypy 0.670 (I also tried 70565cd, which was the most recent commit on master at the time of my testing).
File foo.py:
from typing import Dict, Generic, TypeVar
Key = TypeVar('Key')
class A(Generic[Key]):
@staticmethod
def lookup(d: Dict[Key, int], key: Key) -> None:
x = d.get(key, 0) + 1
x = 1 + "a"
The first time running mypy foo.py produces the expected output:
foo.py:10: error: Unsupported operand types for + ("int" and "str")
Now running mypy foo.py a second time produces a spurious error:
foo.py:8: error: Unsupported operand types for + ("Key" and "int")
foo.py:8: note: Left operand is of type "Union[int, Key]"
foo.py:10: error: Unsupported operand types for + ("int" and "str")
Python 3.7.2, mypy 0.670 (I also tried 70565cd, which was the most recent commit on master at the time of my testing).
File
foo.py:The first time running
mypy foo.pyproduces the expected output:Now running
mypy foo.pya second time produces a spurious error: