Steven D'Aprano writes:

> 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 can decide what method should be the one resolved to *after* visiting all 
superclass methods.

I've already implemented it here, it's a "simple" recursion (no recursion is 
ever simple xD): 
https://github.com/malmiteria/super-alternative-to-super/blob/59ff90029db6e4b63fb72bd807e694e9de9514e8/parent.py#L43

Essentially, as long as parent don't have it, you keep looking higher in the 
inheritance tree, either you find no such method, and you raise an 
AttributeError, if you found it only once, you return it, and if you found 
multiple, you raise the ExplicitResolutionRequired error.

The order in which you visited the parent is irrelevant to the result, what 
matters is only to stop exploring a branch when it ends, or when you found the 
method. Each parent is looked up in its own branch, independantly of any other 
branches.

The end result is absolutely not affected by the order in which you've explored 
those branches

--

> The whole point of inheritance is that (to the degree that it is 
possible) we should not explicitly care about where the methods are 
defined

Agreed. My solution doesn't require you to be explicit about where a method is 
defined.
It only eventually raises an error in case of collision, which you can resolve 
by redefining the method in the child class, only if you intend on calling it 
(not calling a method that would raise an error is fine with my solution, 
whereas current MRO + super fails at class definition time no matter your use 
of that class).
my __as_parent__ allows to explicitely call each one of the parents method 
individually wherever it matters to you

--
> If you do want to explicitly specify where the methods are defined

I don't, at least that's not what my solution is for / requires you to do.

--
> If you want to manage your "inheritance" manually by specifying the 
> order, then just don't use automatic inheritance

That's what i have to resolve to today yeah. The feature has its limits, 
working around it is painful, that's why i'm proposing this change to the 
language
_______________________________________________
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/7ATB5LLZJTZJSEGM3INXIXDNXEQRENJC/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to