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
classA:
def__init__(self, val: int) ->None:
self.val=1@propertydefmy_property(self) ->int:
returnself.val@my_property.setterdefmy_property(self, value: int|str) ->None:
self.val=int(value)
a=A(1)
a.my_property="2"# I expect this to be allowed
but instead I get this error:
test.py:14: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment]
If mypy doesn't support getters/setters being different types (fair enough), why isn't this line def my_property(self, value: int | str) -> None: causing an error because right now, it does nothing and misleading.
The Python typing spec doesn't say anything about asymmetric descriptors or properties, but other type checkers like pyright handle them fine. As Jelle noted, this is a long-standing open issue with mypy. Interestingly, mypy does handle asymmetric descriptors if they are not properties.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Consider this example:
but instead I get this error:
All reactions