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

时间:2012-03-09 09:26:15

标签: 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

控制台输出:

  

使用setter
  使用吸气剂   ThisStatementWillRaise E0202
  使用setter
  使用吸气剂   第二次绑定

Pylint输出:

  

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

1 个答案:

答案 0 :(得分:4)

请参阅http://www.logilab.org/ticket/89092,补丁很快会整合到pylint中以修复此pb

相关问题