Pylint E0202 False Positive? Or is this piece of code wrong?

回眸只為那壹抹淺笑 提交于 2019-12-23 09:34:06

问题


I've been working on a class with properties but we ran into a nasty problem with pylint (0.25.1) In the code below we are defining a class with a property which were introduced in python 2.6 However, pylint whines about the fact that in the __init__ method self.aProperty will overwrite the defined method named aProperty. I've also pasted the output from the console and the output of the pylint messages.

Is this a case of 'please report to the pylint devs' or is this piece of (example) code wrong?

"""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

Console Output:

using setter
using getter
ThisStatementWillRaise E0202
using setter
using getter
Second binding

Pylint Output:

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


回答1:


see http://www.logilab.org/ticket/89092, a patch will soon be integrated into pylint to fix this pb



来源:https://stackoverflow.com/questions/9631666/pylint-e0202-false-positive-or-is-this-piece-of-code-wrong

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!