[Python-projects] is there a way to tell pylint about dynamic attributes?
Paul Warner
paul.warner at cyanoptics.com
Wed Jan 7 19:40:31 CET 2009
I have some python classes which dynamically add attributes in the
__init__ method, and it seems like pylint doesn't see them at all. Is
there some way to tell pylint about these attributes? Other than
re-writing the code to have a simple self.attr = value syntax?
Thanks.
-Paul
$ cat pylintTest.py
class WithDynamicAttrs(object):
attributes = ['one', 'two']
def __init__(self):
for attr in self.__class__.attributes:
setattr(self, attr, 'foo')
def printAttrs(self):
print 'printAttrs one: %s, two: %s' % (self.one, self.two)
instance = WithDynamicAttrs()
instance.printAttrs()
$ python pylintTest.py
printAttrs one: foo, two: foo
$ pylint -e pylintTest.py
No config file found, using default configuration
************* Module pylintTest
E: 9:WithDynamicAttrs.printAttrs: Instance of 'WithDynamicAttrs' has
no 'one' member
E: 9:WithDynamicAttrs.printAttrs: Instance of 'WithDynamicAttrs' has
no 'two' member
$ pylint --version
No config file found, using default configuration
pylint 0.15.2,
astng 0.17.3, common 0.36.0
Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49)
[GCC 4.3.2]
More information about the Python-Projects
mailing list