solving the metaclass conflict

Michele Simionato mis6 at pitt.edu
Mon Jun 9 09:44:40 EDT 2003


mertz at gnosis.cx (David Mertz) wrote in message news:<mailman.1055112100.10468.python-list at python.org>...
> mis6 at pitt.edu (Michele Simionato) wrote previously:
> |> 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.
> 
> Yes and no.  I know that MRO conflicts don't have anything to do with
> metaclasses per se.  But if a version of _generatemetaclass() happened
> to remove all the extraneous superclasses from the metabases tuple, that
> would make many (all?) MRO conflicts do away.
> 

Does not smell good to me... MRO conflicts are good, they forbid the
programmer to write ambiguos hierarchies. 

> I think removing those extra superclasses would be a good thing.  But I
> don't feel strongly; and there might be some reason I have overlooked
> why it wouldn't be so good.
> 
> |class C(object,type): pass
> |gives a MRO conflict (under Python 2.3).
> 
> Hmmm... actually, the question never came to my mind.  I'm not sure what
> my first guess would have been--especially since, as you hint, Python
> 2.2 behaves differently.  Just a little more for readers:
> 
>   class C(type, object): pass
> 
> Is perfectly happy under both 2.2 and 2.3.  Again, obvious to Michele,
> but probably not to some other readers.
> 

Not obvious at all! I was bitten by this, even *after* having written
http://www.python.org/2.3/mro.html and having explained there why
right triangular diagrams like
                      
                      B 
                      | \
                      |  B1 
                      | /
                      C 
                   
are bad. The C3 MRO is unfortunately not intuitive, even having experience
with it. But I don't know of any other better alternative.


                               Michele




More information about the Python-list mailing list