On Mon, Apr 04, 2022 at 09:45:32PM -0000, malmiteria  wrote:

> All we have today is the screwhammer, and in cases the screw part 
> don't work, you're telling me to get rid of it all. hammer part 
> included.

That's not how I see it.

I see that we have a screwdriver (inheritence, including multiple 
inheritence) which is designed for the cases where you, the programmer, 
don't want to manually specify which superclass method to call, you want 
the interpreter to do it using the defined linearisation.

And then we have a hammer, composition/delegation, for when you *do* 
want to control what method is called.

As I see it, it is you who wants to combine the two into a screwhammer, 
so that you can use the same mechanism (super and inheritence) both for 
the inheritence case (follow the linearisation) and the composition/ 
delegation case (manually specify the method you want to call).

That is exactly what you did in your Gobelin example, with the HalfBreed 
sometimes using plain old inheritence using super, and sometimes trying 
to jump part of the MRO and call a specific method, but you still used 
super for that.

```
class HalfBreed(ProudGobelin, CorruptedGobelin):
    def scream(self):
        if random.choice([True, False]):
            # This is plain old inheritence, in Python 3 we can
            # write it as just super().scream()
            super(HalfBreed, self).scream()
        else:
            # And this is a failed attempt to ignore inheritence
            # and delegate to ProudGobelin.scream using super.
            super(ProudGobelin, self).scream()
```

So in this example at least, you try to use the same screwdriver (super) 
for both inheritence (driving screws) and delegation (hammering nails).



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

Reply via email to