error: Incompatible types in assignment (expression has type "float", variable has type "int")
Notes
Mypy seems to be type checking the assignment using the type declared in def foo(self) -> int: instead of the declared types in the setter: def foo(self, value: Union[int, float]) -> None:
Your hunch is correct: for properties, mypy uses the type declared in the initial @property definition as the final type for the attribute, regardless of what the @property.setter does.
I suppose we could fix this though it might require a bunch of one-off changes in odd corners of the code since properties are unique in this respect.
Activity
gvanrossum commented on Oct 27, 2017
Your hunch is correct: for properties, mypy uses the type declared in the initial @property definition as the final type for the attribute, regardless of what the @property.setter does.
I suppose we could fix this though it might require a bunch of one-off changes in odd corners of the code since properties are unique in this respect.
srittau commented on Feb 23, 2018
This seems similar to issue #3004, which has more discussion.
gvanrossum commented on Feb 23, 2018
Oh, yeah, it's a duplicate.