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 it complains: 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. | |
| priority | normal |
|---|---|
| type | bug |
| appeared in | <not specified> |
| done in | 0.21.0 |
| load | 0.500 |
| load left | 0.000 |
| closed by | <not specified> |


#8961 tell pylint about dynamic attributes