On Sat, Mar 26, 2022 at 11:16 AM malmiteria <martin.milon@ensc.fr> wrote:
the alternative to super really is not the important part of my proposal, it's the alternative to MRO.

wait, what? 
 
We may need some more clarity as to what you are after. You need SOME method resolution order, and Python's MRO is pretty simple and straight froward.
```
class A:
    def method(self):
        print("A")

class B:
    def method(self):
        print("B")

class C(A, B):
    pass
``` 
Today, a code such as ```C().method()``` works without any problems
except of course when the method you wanted to refer to was the method from B.
If class A and B both come from libraries you don't own, and for some reason have each a method named the same (named run, for example)
the run method of C is silently ignoring the run method of B.

But the author of C should certainly test that, and choose what order to put them in. It's possible they would want one method from A, and one from B, but then they could override those methods if they need to.

I'm not sure how you could be more explicit than that.

I believe it would make the programmers life easier to have an error at this time, or anything tbh, to make explicit this resolution, because it really is not explicit from most programmers perspective

But much (most) if the time — you want either to call all of the superclasses parent methods (super()) or one of them (the usual direct call) - it would be not very helpful, and quite annoying to get errors when I explicitly told Python what I want to do.


 in case for example you're calling super on a class that's not a parent for example,

I don’t think that’s even possible. 

 but more about making it easier *when* writing code.

Even a tiny modicum of testing would take care of that. 

And finally, super is not a proxy to parents, even plural, it's a proxy to the next in mro order.

It’s a proxy to all of the classes in the MRO, which is the parents.

in this case :
class Top:
    def method(self):
        print('Top')
class Left(Top):
    def method(self):
        print('Left')
        super().method()
class Right(Top):
    def method(self):
        print('Right')
        super().method()
class Bottom(Left, Right):
    def method(self):
        print('Bottom')
        super().method()

Bottom().super() would print "Bottom", "Left", "Right", "Top".
super, in Left, reffers to Right, which is not a parent of Left (and is completely absent of it's definition)

Which is we what I mean by all of them. If you didn’t use super in the whole chain— it would stop when it found the method. If you do, then they are all calked, and each one only once. 

Steven A mentioned the two seminal articles “super considered harmful” and “super considered helpful” — the thing is, they both say the same thing— in order for super() to work you have to follow certain rules. And then it works predictably. Whether that’s helpful or not depends on your use case.

-CHB


--
Christopher Barker, PhD (Chris)

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
--
Christopher Barker, PhD (Chris)

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython