我一直在研究一个带有属性的类,但是在下面的代码中我们遇到了一个pylint(0.25.1)的严重问题,我们正在用python2.6中引入的一个属性来定义一个类
然而,pylint抱怨说在__init__
方法中self.aProperty
将重写名为property的已定义方法。我还粘贴了控制台的输出和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
控制台输出:
using setter
using getter
ThisStatementWillRaise E0202
using setter
using getter
Second binding
Pylint输出:
E0202: 7,4:Example.aProperty: An attribute affected in test1 line 26 hide this method
E0202: 13,4:Example.aProperty: An attribute affected in test1 line 26 hide this method
请看http://www.logilab.org/ticket/89092,一个补丁将很快集成到pylint中来修复这个pb
相关问题 更多 >
编程相关推荐