Why does PyCharm give a warning here?

已回答

I have some code here, which throws a warning about an instance attribute being defined outside of __init__, shouldn't that warning be supressed by default if @property/@x.setter decorated is used?

 

class A:
def __init__(self, x):
self.x = x

@property
def x(self):
return self._x

@x.setter
def x(self, value):
self._x = min(1000, value) # Instance attribute __x defined outside __init__

a = A(9999)
print(a.x) # -> 1000
0

Hi Rrebase! This is a known problem: PY-25263. Please vote for this issue.

1

请先登录再写评论。