new-style-classes mixin

J.Jacob joost_jacob at hotmail.com
Tue Aug 6 15:16:25 CEST 2002


"Lamy Jean-Baptiste" <jiba at tuxfamily.org> wrote:
> A solution i have used sometimes is to create a new class in doMixin,
> rather changing the existent one (e.g. with "new.classobj" from the new
> module).
> It is not exactly the same, though, since other object of the same class
> aren't be modified.

Oh you are thinking about changing the class itself, thus changing all
class instances.  My doMixin function only changes an object of <type
"instance">, adding a class to its .__bases__.
I also have been playing with the idea of just adding stuff
dynamically to an instance instead of changing its class.  But adding
to __bases__ did look so elegant.

> By the way, is there a good reason for __bases__ to be read-only ?
> 

Yes, they will have to adapt the algorithm that does __bases__
assignment for classic classes.  I did file a bug report on
sourceforge about it so maybe it is 'fixed' soon, no idea if this is
complicated.

Also see
http://www.linuxjournal.com/article.php?sid=4540
for more about it
I like that article but I wonder if many pythoneers did read it, I
mean I did not find many other people assigning to __bases__...maybe
the percentage linux pythoneers is less that we think?



More information about the Python-list mailing list