[Python-ideas] Consider (one day) adding an inheritance order class precedence mechanism
mistersheik at gmail.com
Fri Nov 17 17:39:04 EST 2017
On Thu, Nov 16, 2017 at 1:11 AM Greg Ewing <greg.ewing at canterbury.ac.nz>
> Steven D'Aprano wrote:
> > These are not equivalent:
> > B < S, E
> > B < E, S
> Not in general, but in many cases they will be, e.g. if
> E and S have no method names in common. I think the OP is
> implying that his case is one of those.
> Maybe what's really wanted is a way to say "B inherits from
> S and E, but it doesn't care what order they go in". Then
> the MRO generating algorithm could in principle swap them
> if it would result in a consistent MRO.
Interesting idea, but unfortunately, reordering base classes doesn't solve
all of the problems that a precedence specification does. For example, the
original example was:
R < E, C
B < S, E
S < C
Z < B, R
If we make it slightly more complicated:
class Y: pass
class X(Y): pass
class E(X): pass
class C: pass
class R(E, C): pass
class S(C, Y): pass
class B(S, E): pass
class Z(B, R): pass
Then, S and E can't be swapped.
> Or maybe the MRO generator could decide for itself if the
> order of two base classes can be swapped by inspecting
> their attributes to see if any of them clash?
In general, I think that this would be a cool project, but is much hard
than the user declaring a consistent order.
> Python-ideas mailing list
> Python-ideas at python.org
> Code of Conduct: http://python.org/psf/codeofconduct/
> You received this message because you are subscribed to a topic in the
> Google Groups "python-ideas" group.
> To unsubscribe from this topic, visit
> To unsubscribe from this group and all its topics, send an email to
> python-ideas+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas