initializing mutable class attributes

Dan Perl dperl at rogers.com
Wed Sep 1 12:19:57 EDT 2004


Sorry, Anthony, but I don't think that is relevant for my example.  I wasn't
referring to replacing the superclass with another one, which is where
'super( )' would have been useful because it detects the superclass only at
run-time.  I was referring to changing the implementation of the superclass,
in which case 'super( )' doesn't make any difference.

See, however, a posting from Jorge Godoy, where he makes the great point
that the problem is removed by always subclassing the base class from
'object'.  So the new-style class mechanism is taking care of this problem.

Dan

"Anthony Baxter" <anthonybaxter at gmail.com> wrote in message
news:mailman.2726.1094051698.5135.python-list at python.org...
> On Wed, 01 Sep 2004 14:54:06 GMT, Dan Perl <dperl at rogers.com> wrote:
> > Not in Python.  A user of my library has to invoke the parent's class
> > __init__ in their own __init__.  What happens if, in a future release, I
get
> > rid of the __init__ in the parent class?  Or the other way around.  An
early
> > release does not have a parent __init__, the users don't invoke it
because
> > they can't, and then, in a future release, I add the parent __init__
because
> > I added some attributes.  It breaks all the users' code.  This is poor
> > encapsulation.
>
> Use 'super()', in that case.
>
> http://www.python.org/dev/doc/devel/lib/built-in-funcs.html#l2h-70





More information about the Python-list mailing list