Warning when new attributes are added to classes at run time

Diez B. Roggisch deets at nospam.web.de
Wed Jul 19 17:37:51 EDT 2006


Matthew Wilson schrieb:
> I sometimes inadvertently create a new attribute on an object rather
> update a value bound to an existing attribute.  For example:
> 
>     In [5]: class some_class(object):
>        ...:      def __init__(self, a=None):
>        ...:          self.a = a
>        ...:
> 
>     In [6]: c = some_class(a=1)
> 
>     In [7]: c.a
>     Out[7]: 1
> 
>     In [8]: c.A = 2
> 
> I meant to update c.a but I created a new c.A.  I make this mistake
> probably hourly.

Try pylint & pychecker.

Diez



More information about the Python-list mailing list