Daan Timmer
Daan Timmer

Reputation: 15047

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

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

Upvotes: 9

Views: 6208

Answers (1)

sthenault
sthenault

Reputation: 15125

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

Upvotes: 5

Related Questions