On Sat, 26 Mar 2022 at 18:01, malmiteria <martin.mi...@ensc.fr> wrote:

> Hi,
>
> Before anything, i made a github repository about this topic here :
> https://github.com/malmiteria/super-alternative-to-super
>
> The core of what i wanna discuss here is that i don't think mro and super
> (mainly because it relies on mro) are very pythonic. Mainly that some
> behaviors of the mro are too implicit, and are silencing what really should
> be errors.
>

Coming in to the start late, sorry. But having read a lot of the discussion
in this thread I think the disconnect is really back in your first post:
why don't let programmers solve it themselves? We do. super() is optional.

In languages where there are multiple instances of a parent type in a
diamond situation, e.g. C, every parent instance has to be called every
time.

In languages where it is possible to have just one instance of a parent
type, like Python (always), or C++ (with virtual), calling base methods
multiple times will occur (e.g.
https://stackoverflow.com/questions/55829798/c-diamond-problem-how-to-call-base-method-only-once
), so developers need to come up with ways to avoid it (e.g. not calling
parent methods from some specific methods).

In Python we picked a particular way of projecting the diamond inheritance
pattern that has some very useful properties, and then allowed programmers
to use that, or not, as they choose.

The useful properties being that parents are always ordered before *all*
children, and that the order is deterministic; super() then just walks back
up the ordered list to make calls.

The contrived examples in your git repo suggest to me a misunderstanding of
diamond inheritance (in general) - if you want to define a new protocol,
you need an abstract base:

```
class Family:
    def method(self): pass
class C(Family):
    def method(self):
        print('C')
        super().method()
class B(Family):
    def method(self):
        print('B')
        super().method() # HERE
class A(B,C):
    def method(self):
        print('A')
        super().method()

A().method()
print("--")
B().method()
print("--")
C().method()
```

otherwise, super() is inappropriate and you should just call B.method(self)
from A.method, etc.

-Rob
_______________________________________________
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/DWWDYRH3U4FHSPKWX2ZTL5CFCVFDK456/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to