Can one class have multiple metaclasses?

D

David Hirschfield

Is it possible for one class definition to have multiple metaclasses?

I don't think it is, but I'm just checking to make sure.
From what I know, you can only define "__metaclass__" to set the
metaclass for a class, and that's it, is that correct?

-David
 
A

Alex Martelli

David Hirschfield said:
Is it possible for one class definition to have multiple metaclasses?

I don't think it is, but I'm just checking to make sure.

You're right, it isn't.
From what I know, you can only define "__metaclass__" to set the
metaclass for a class, and that's it, is that correct?

Yes, it's correct. Just as an instance is an instance of one (leafmost)
class, so a class is an instance of one (leafmost) metaclass -- if you
want multiple classes or metaclasses, you must inherit.

The last recipe in the 2nd ed of Python Cookbook shows how to design an
automatic "metaclass conflict reconciler" to do the inheritance on your
behalf, btw.


Alex
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top