You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
Current Solution
Silence the error with # type: ignore
The text was updated successfully, but these errors were encountered:
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.
Expected Behaviour
setter
withUnion[]
setter
Actual Behaviour & Repro Case
Python Code
Stdout
(i.e., valid Python code)
Mypy CLI
Result
Notes
Mypy
seems to be type checking the assignment using the type declared indef foo(self) -> int:
instead of the declared types in thesetter
:def foo(self, value: Union[int, float]) -> None:
Current Solution
# type: ignore
The text was updated successfully, but these errors were encountered: