initializing mutable class attributes

Dan Perl dperl at rogers.com
Mon Aug 30 12:28:18 EDT 2004


Thanks, Peter.  pychecker detecting the wrong use makes the argument that
there is no excuse for making the mistake of not calling the parent's
__init__ in subclasses.  I am regularly using pychecker on my code, but I
never saw that warning because I did use __init__ correctly.

But I did make the mistake once of using a class attribute with an empty
dictionary to initialize an instance attribute just because I was doing the
same thing with immutable attributes.  Fortunately, I caught it soon enough
and I will not make that mistake again.  But it was kind of an embarrassing
mistake and I learned my lesson only after that.

Dan

"Peter Otten" <__peter__ at web.de> wrote in message
news:cgvdun$1mb$01$1 at news.t-online.com...
> You have to call base-class-__init__() in every non-trivial inheritance
> scheme. Should you forget it, pychecker is always there to remind you
> [....]
> And here's what pychecker says:
>
> $ pychecker t1.py
> Processing t1...
>
> Warnings...
>
> t1.py:9: Base class (t1.Y) __init__() not called
>
> Clear enough.
>
> Peter
>





More information about the Python-list mailing list