[Python-projects] is there a way to tell pylint about dynamic attributes?

Duncan Findlay duncf at debian.org
Mon Jan 12 20:53:24 CET 2009


On Jan 9, 2009, at 8:54 AM, Alexandre Fayolle wrote:

> Le Wednesday 07 January 2009 19:40:31 Paul Warner, vous avez écrit :
>> 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?
>
> Hi,
>
> The short answer is (unfortunately) "no".
>
> A longer and more interesting answer would be asking you how you  
> would like to
> tell pylint the list of valid attributes for your class?

Presumably something like the following could work.

class MyClass(object):

     # pylint: dynamic-attributes = foo, bar, baz
     def __init__(self, **kwargs):
         for key, val in kwargs.iteritems():
              setattr(self, key, value)

Duncan


More information about the Python-Projects mailing list