Python - Properties and Pylint

Am I doing something non-pythonic here? Or is it a pylint error?

class Thing(object):
    """
    Thing used for stackoverflow example.
    """

    def __init__(self, something):
        """
        Initialize Thing.
        """

        # Set defaults.
        self._something = None

        # Set values using getter/setter methods - this allows for checks.
        self.something = something

    @property
    def something(self):
        """
        Get something
        """
        return self._something

    @something.setter
    def something(self, value):
        """
        Set something.
        """
        # Some value checking here.
        self._something = value

I got the impression that using property decorators was a smart way to implement properties. Pilint says otherwise. Pylint gives me the following errors:

Thing: Too many instance attributes (2/1)
Thing.something: An attribute affected in thing line 10 hide this method

If I implement the property in the old way, I do not get the same problem.

class Thing(object):
    """
    Thing used for stackoverflow example.
    """

    def __init__(self, something):
        """
        Initialize Thing.
        """

        # Set defaults.
        self._something = None

        # Set values using getter/setter methods - this allows for checks.
        self.set_something(something)

    def get_something(self):
        """
        Get something
        """
        return self._something

    def set_something(self, value):
        """
        Set something.
        """
        # Some value checking here.
        self._something = value

    something = property(get_something, set_something)
+4
source share

All Articles