[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Odd handling of type.__init__ bases

quick

2/28/2008 10:50:00 PM

I encountered an oddity in attempting to use a metaclass to perform mix-in
inheritance for classes. I've attached a small demonstration file. Have I
misunderstood the bases argument for type.__init__ or should this be submitted
as a bug?

Python 2.5 (r25:51908, Feb 22 2007, 19:05:27)
[GCC 4.1.2] on linux2

-KQ





-------------------------------------------------
This mail sent through IMP: http://hord...
1 Answer

Arnaud Delobelle

2/28/2008 11:38:00 PM

0

On Feb 28, 10:50 pm, qu...@sparq.org wrote:
> I encountered an oddity in attempting to use a metaclass to perform mix-in
> inheritance for classes.  I've attached a small demonstration file.  Have I
> misunderstood the bases argument for type.__init__ or should this be submitted
> as a bug?

After a quick look at your example:

* you are mixing classic classes (abase) and new-style classes (A and
B), which often creates problems.

* type.__init__ does not set the base classes, type.__new__ does
this. What you want to achieve could be done with:

class meta3(type):
def __new__(cls, name, bases, dict):
bases += (abase,)
return type.__new__(cls, name, bases, dict)

HTH

--
Arnaud