general class functions

Alex Martelli aleaxit at yahoo.com
Wed Nov 3 17:06:39 EST 2004


syd <syd.diamond at gmail.com> wrote:
   ...
> But more importantly, why is subclassing object a good practice in

"Subclassing object" gives you newstyle classes, instead of the default
classic classes we're stuck with, for backwards compatibility, until a
Python 3.0 comes out that can break such compatibility.  Other ways to
make a class newstyle include inheriting from any other newstyle type
(including builtin types) and setting __metaclass__=type .

The newstyle object model fixes many tiny but irritating warts that the
classic object model is stuck with, such as instance dicts always taking
precedence over classes (and thus the inability to use descriptors, e.g.
properties, to full advantage), the classic model's oversimplified
concept of method resolution order in multiple-inheritance situations,
and the intrinsic asymmetry of class->metaclass vs instance->class
semantics in the classic object model.


Alex



More information about the Python-list mailing list