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

Paul Warner paul.warner at cyanoptics.com
Fri Jan 23 23:13:52 CET 2009


First, thank you folks for answering these questions.  Some how my
list subscription got hosed up by my spam filter, so I just got a
chance to read these now.  My bad, sorry about that.

A comment like
# pylint: dynamic-attributes = foo, bar, baz

would be cool I think, or '*' as an option as well.

What would be even handier would be to specify the name of a python
list or dict where the list members or keys are the attribute names.
Of course this would need to be a class attribute, not an instance
attribute.  For example:

class MyClass(object):
    attrs = ['foo', 'bar', 'baz']
    # pylint: dynamic-attributes = attrs
    def __init__(self):
        for attr in self.__class__.attrs:
            setattr(self, attr, 'some value')

For the case that attributes are defined outside the class and passed
in to __init__ I can not think of a way to handle that one.

-Paul

On Mon Jan 12, 2009 Maarten ter Huurne wrote:

> I would prefer to have a way to tell pylint that a class has dynamic
> attributes without explicitly naming the attributes. In the best case
> explicitly naming the attributes is duplicating information, in the worst
> case it is not even possible to name the attributes since they might be
> different for different executions of the program (read from a user-provided
> data file, for example).
>
> A possible syntax for this would be similar to what you proposed, but with a
> slightly different comment:
>       # pylint: dynamic-attributes
> or with a wildcard filter:
>       # pylint: dynamic-attributes = *
> or with a regex filter:
>       # pylint: dynamic-attributes = .*
> or similar to existing warning-suppression syntax:
>       # pylint: disable-msg=E1101
> In the last case, this suppression should not suppress warnings from code
> inside the class, but from code outside the class accessing attributes on
> the class.
>
> Bye,
> 		Maarten


More information about the Python-Projects mailing list