Why Does Pycharm Raise A Warning When Using @property Here?
In tutorials I have seen two types of instance attribute naming for the purpose of using @property. Here is code showing examples of both. They also seem to work differently. class
Solution 1:
It seems to be a bug in PyCharm: https://youtrack.jetbrains.com/issue/PY-25263.
A temporary solution I found was to add self._x = None in the __init__. So the code would be:
classA:
def__init__(self, x):
self._x = None
self.x = x
@propertydefx(self):
return self._x
@x.setterdefx(self, x):
if x > 1000:
self._x = 1000else:
self._x = x
a = A(9999)
print(a.x) # -> 1000
Post a Comment for "Why Does Pycharm Raise A Warning When Using @property Here?"