Odd handling of type.__init__ bases

Q

quick

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
 
A

Arnaud Delobelle

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top