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
from typing import Union
class Test:
def __init__(self, something: Union[int, str]):
self.something = something
@property
def something(self) -> str:
return self._something
@something.setter
def something(self, val: Union[int, str]) -> None:
if isinstance(val, int):
self._something = str(val)
else:
self._something = val
fails with the following error:
error: Incompatible types in assignment (expression has type "Union[int, str]", variable has type "str")
It seems that mypy is confusing the type of the getter with the type of the setter. Any idea what might be causing this?
Thanks!
The text was updated successfully, but these errors were encountered:
AbdulRahmanAlHamali
changed the title
Bug: Type of getter is getting used instead of the setter
Bug: mypy is confusing the type of the getter with that of the setter
Jul 14, 2019
Properties with different getter and setter types were never supported see #3004. It was not caught before because there was a bug that all properties defined after they use in __init__() were silently turned into Any.
Hello, starting v0.720, the following code:
fails with the following error:
It seems that mypy is confusing the type of the getter with the type of the setter. Any idea what might be causing this?
Thanks!
The text was updated successfully, but these errors were encountered: