[Python-projects] is there a way to tell pylint about dynamic attributes?
Maarten ter Huurne
maarten at treewalker.org
Mon Jan 12 23:20:15 CET 2009
On Monday 12 January 2009, Duncan Findlay wrote:
> 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)
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