raising an exception when multiple inheritance involves same baseThank
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Sun May 25 13:53:57 EDT 2008
En Sun, 25 May 2008 13:32:39 -0300, Paul McGuire <ptmcg at austin.rr.com> escribió:
> Here's a more general version of your testing code, to detect *any*
> diamond multiple inheritance (using your sample classes).
>
> for cls in (A,B,C,D):
> seen = set()
> try:
> bases = cls.__bases__
> for b in bases:
> if hasattr(b,"__mro__"):
> for m in b.__mro__:
> if m in seen:
> raise Exception("diamond multiple
> inheritance")
> seen.add(m)
> except Exception, e:
> print cls,"has diamond MI"
> else:
> print cls,"is ok"
I think you should exclude the `object` class from the test, because all new-style classes inherit from it and *every* case of multiple inheritance forms a diamond.
--
Gabriel Genellina
More information about the Python-list
mailing list