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
see http://www.logilab.org/ticket/89092, a patch will soon be integrated into pylint to fix this pb
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With