Pylint E0202误报?或者这段代码是错的?

Daa*_*mer 6 python pylint

我一直在研究一个有属性的类,但是我们遇到了一个令人讨厌的pylint问题(0.25.1)在下面的代码中我们定义了一个带有属性的类,它们是在python 2.6中引入的.但是,pylint抱怨这个事实在该__init__方法self.aProperty中将覆盖名为aProperty的已定义方法.我还粘贴了控制台的输出和pylint消息的输出.

这是"请向pylint devs报告"还是这段(示例)代码错误?

"""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
Run Code Online (Sandbox Code Playgroud)

控制台输出:

使用setter
使用getter 使用setter 使用setter 使用getter进行 第二次绑定使用
setterWillRaise E0202


Pylint输出:

E0202:7,4:Example.aProperty:test1第26行中受影响的属性隐藏此方法
E0202:13,4:Example.aProperty:test1第26行中受影响的属性隐藏此方法

sth*_*ult 5

参见http://www.logilab.org/ticket/89092,一个补丁很快就会被集成到 pylint 中来修复这个 pb