我在这里做一些非pythonic的事情吗?或者这是一个pylint bug?
class Thing(object):
"""
Thing used for stackoverflow example.
"""
def __init__(self, something):
"""
Initialize Thing.
"""
# Set defaults.
self._something = None
# Set values using getter/setter methods - this allows for checks.
self.something = something
@property
def something(self):
"""
Get something
"""
return self._something
@something.setter
def something(self, value):
"""
Set something.
"""
# Some value checking here.
self._something = value
我的印象是使用属性装饰器是实现属性的合理方法。 Pylint说不然。 Pylint给了我以下错误:
Thing: Too many instance attributes (2/1)
Thing.something: An attribute affected in thing line 10 hide this method
如果我以旧方式实现该属性,我不会遇到同样的问题。
class Thing(object):
"""
Thing used for stackoverflow example.
"""
def __init__(self, something):
"""
Initialize Thing.
"""
# Set defaults.
self._something = None
# Set values using getter/setter methods - this allows for checks.
self.set_something(something)
def get_something(self):
"""
Get something
"""
return self._something
def set_something(self, value):
"""
Set something.
"""
# Some value checking here.
self._something = value
something = property(get_something, set_something)