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
Traceback (most recent call last):
File "/Users/jukka/src/mypy/t/t5.py", line 11, in <module>
C()
File "/Users/jukka/src/mypy/t/t5.py", line 9, in __init__
self.x = 4
^^^^^^
AttributeError: property 'x' of 'C' object has no setter
This doesn't generate an exception at runtime, however (and mypy correctly accepts this):
Also, this already generates an error from mypy, as expected:
classB:
@propertydefx(self) ->int:
return0classC(B):
def__init__(self) ->None:
self.x=4# error: "x" is read-only
It seems that mypy should only allow overriding a read-only property with an attribute declared in the class body if the attribute has an initializer in the class body. For consistency, we should probably also use the same rule for overriding read-write properties.
The text was updated successfully, but these errors were encountered:
Mypy doesn't complain about this, even though it fails at runtime with an exception:
Exception:
This doesn't generate an exception at runtime, however (and mypy correctly accepts this):
Also, this already generates an error from mypy, as expected:
It seems that mypy should only allow overriding a read-only property with an attribute declared in the class body if the attribute has an initializer in the class body. For consistency, we should probably also use the same rule for overriding read-write properties.
The text was updated successfully, but these errors were encountered: