Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attribute-defined-outside-init warning wrongly triggered when using properties #409

Closed
pylint-bot opened this issue Dec 5, 2014 · 2 comments
Labels

Comments

@pylint-bot
Copy link

Originally reported by: James Nande (BitBucket: jnande)


Hi,

Pylint seems unable to detect Python properties properly. For instance, an attribute-defined-outside-init is triggered on the last line of the following class declaration :

#!python
class Mine:
    def __init__(self, x):
        self.x = x

    @property
    def x(self):
        return self.__x

    @x.setter
    def x(self, x):
        self.__x = x

Besides using a disable-msg comment, the only way I've found to circumvent this is to put a spurious self.__x = None before self.x = x.


@BlacKCaT27
Copy link

I just ran into this today. Seems it hasn't gotten much attention though it's a known (albeit minor) issue. Is this just something no one has gotten around to or is there a technical limitaion which negates being able detect this condition and not show the linter warning?

Actually, while I don't know what PEP has to say about it, it might be nice if there was a way to detect if a method was only ever called from init that any self. assignments not have their warnings shown either, since that line was technically executed only during object initialization. This would naturally encapsulate the property setter call, as well.

heilaaks added a commit to heilaaks/snippy that referenced this issue Jan 7, 2018
There were few bugs in the new implementation that were masked
by old implementation. These are now corrected.

The tool must be aware if specific parameter were given to
Config() source base class. These parameters are: digest,
data, sall, stag and sgrp. The default value for these must
be None or they must be left out from the parameter dictionary
give to the class inherited from the Config source base class.

There is an open fault in Pylint /1/. It does not see the usage
of property decorator with self._parameter when the __init__
has been set with self.parameter. The later is valid syntax
for the Python property decorator /2/.

/1/ pylint-dev/pylint#409
/2/ https://www.python-course.eu/python3_properties.php

Signed-off-by: Heikki Laaksonen <laaksonen.heikki.j@gmail.com>
@rcronk
Copy link

rcronk commented May 14, 2018

I'm also hitting this. Please fix. I bet it's a difficult check though since you can call anything from anywhere and you'd have to check it all to make sure things are called from within init, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants