pylint #9018 when using defining-attr-method, method order matters [resolved]
Consider this simple class:
class C: def __init__(self): self.x = 0 self.reset() def set_y(self, y): self.y = y def set_x(self, x): self.x = x def reset(self): self.x = 0 self.y = 0
If you run pylint over it like so:
pylint --defining-attr-methods=__init__,reset resetwhen.py
resetwhen.py:9: [W, C.set_y] Attribute 'y' defined outside __init__
If, however, you reorganize it slightly so that reset() occurs before set_y, pylint is happy. I can understand why this error is emitted. Pylint sees the definition of self.y in set_y before it encounters reset and thus emits the error message.
It seems to me that giving a bunch of attributes initial values is generally of secondary importance to a class's functionality. It should be ok to push such methods to the end of the file. I think pylint should collect the location of attribute initialization as it runs and only report on attributes which are not ever assigned in the methods specified by defining-attr-methods, ignoring when they are encountered.
|closed by||<not specified>|
- logilab-astng #903 cache for external libraries
- pylint #4983 new py2.5 check: test "yield" in "try" body with yield in exception handlers.
- pylint #9776 warning if return or break inside a finally
- pylint #4738 more synthetic output, à la pychecker
- pylint #17958 pylint -e must not silence Fatal messages