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.
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.
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.
Most helpful comment
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.