On Mon, 28 Mar 2022 at 10:41, Steven D'Aprano <st...@pearwood.info> wrote:
>
> On Sun, Mar 27, 2022 at 01:33:05PM -0000, malmiteria  wrote:
>
> > C3 linéarization might be mathematically proven to be optimal, as in,
> > it's the best way to order a graph. Sure. But why would we order the
> > inheritance tree?
>
> How else are you going to get inheritance without a linear order? The
> interpreter can only call superclass methods one at a time, in
> some linear order. You might have a tree that looks like this in part:
>
>     # class C(A, B): ...
>
>     A     B
>      \   /
>       \ /
>        C
>
> but C.method() cannot call A.method() and B.method() *simultaneously*,
> it must call one followed by the other in *some order*.
>

"Linearizing" applies to the whole tree. An alternative would be to
consider the immediate parents of this class only, not of any other,
which could be done by having super return all of the corresponding
attributes. This would work nicely for some things, and very very
badly for others.

It shouldn't be called super, but it absolutely could be called
parents or something, and it'd be used in a completely different form
of cooperative multiple inheritance - instead of each level calling
super to pass control to the next one, each one would do its own thing
and put stuff into a shared collection or something.

There are lots of ways things can be done, but Python's super is, as
the OP says, tied closely to the concept of linearizing the entire
tree and walking the MRO.

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/NVBNEPTGWUCJNFSNGW2ZVNRTN7R2H6TK/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to