solving the metaclass conflict

Michele Simionato mis6 at pitt.edu
Sun Jun 8 07:56:06 EDT 2003


mertz at gnosis.cx (David Mertz) wrote in message news:<mailman.1055044454.21616.python-list at python.org>...
> |>  --> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/204197
> |FYI, note that your implementation doesn't:
> 
> While Michele wrote the abovementioned module, I helped him enhance his
> initial version, so I've thought about it some.  

David, your help was greatly appreciated and you are aknowledged in the
recipe!

> |* Handle multi-level metaclasses (e.g. metametaclasses)
> 
> This I don't get at all.  I've never used a metametaclass (and doubt I
> will).  But even assuming I did, the type() of a metaclass resolves to
> such a metametaclass, and the proposed code should work fine.
> 
> Is something else intended here?

Yes, when I wrote the first version of the code, a couple of months ago, 
I also found a couple of examples involving meta-metaclasses where
_generatemetaclass fails; I don't find them now, but as soon as I do, I
will post them.

  <snip>

> Of course:
> 
>     M = _generatemetaclass((),(A,B,C),0)
>     #-> TypeError: MRO conflict among bases B, C, A
> 
> Which is a bad thing.  Is that the real concern?

Of course not, since this is an issue with the C3 method resolution
order (http://www.python.org/2.3/mro.html) which in principle has nothing
to do with metaclasses. It is correct to have an error in this case, since 
you are putting a less specific class before the more specialized class. 
This is also the reason why

class C(object,type): pass

gives a MRO conflict (under Python 2.3). I am sure you know already that,
it was for the sake of c.l.p. readers ;)

Cheers,


                                                     Michele




More information about the Python-list mailing list