我一直在研究一个带有属性的类,但我们遇到了 pylint 的一个棘手问题(0.25.1)在下面的代码中,我们定义了一个带有 python 2.6 中引入的属性的类
然而,皮林特抱怨说,在__init__
method self.aProperty
将覆盖名为 aProperty 的已定义方法。我还粘贴了控制台的输出和 pylint 消息的输出。
这是“请向 pylint 开发人员报告”的情况还是这段(示例)代码错误?
"""example module"""
class Example(object):
"""example class"""
@property
def aProperty(self):
"""get"""
print "using getter"
return self._myPropertyValue
@aProperty.setter
def aProperty(self, value):
"""set"""
print "using setter"
self._myPropertyValue = value
def secondPublicMethodToIgnorePylintWarning(self):
"""dummy"""
return self.aProperty
def __init__(self):
"""init"""
self._myPropertyValue = None
self.aProperty = "ThisStatementWillRaise E0202"
anExample = Example()
print anExample.aProperty
anExample.aProperty = "Second binding"
print anExample.aProperty
控制台输出:
使用设置器
使用吸气剂
本声明将提出 E0202
使用设置器
使用吸气剂
第二次绑定
皮林特输出:
E0202: 7,4:Example.aProperty: test1 第 26 行中受影响的属性隐藏此方法
E0202:13,4:Example.aProperty:test1第26行中受影响的属性隐藏此方法
see http://www.logilab.org/ticket/89092 http://www.logilab.org/ticket/89092,很快就会有一个补丁集成到 pylint 中来修复这个 pb
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)