
Matsuoka Takuo writes:
I don't think this is better than the failing code in any way. It will fail in the same way. Yeah! i completely forgot that :p I've been redoing this exemple so many times now, it's hard to always keep the brain turned on when writing it. Thanks for pointing it out.
I think she should have done as follows, and that's close to the solution I shared with you first. I understand that this solution works, as in, it provides a way for the lib user's to make HalfBreed work as intended. But i think that it requires way too much efforts, and essentially hints at a flaw of today's design.
With my proposal, you wouldn't have to change the lib at all: ``` class HighGobelin: def scream(self): print("raAaaaAar") class CorruptedGobelin(HighGobelin): def scream(self): print("my corrupted soul makes me wanna scream") super().scream() class ProudGobelin(HighGobelin): def scream(self): print("I ... can't ... contain my scream!") super().scream() ``` would be enough. A lib user could write : ``` class HalfBreed(ProudGobelin, CorruptedGobelin): def scream(self): if random.choice([True, False]): super(ProudGobelin, self).scream() # OR : super(ProudGobelin).scream() # OR : self.__as_parent__(ProudGobelin).scream(), in the toy implementation i made here : https://github.com/malmiteria/super-alternative-to-super/blob/master/parent.... else: super(CorruptedGobelin, self).scream() ``` This would work like intended. Of course the question now is, how do we limit the breaking changes, and how to we leave open the option to have a class appearing multiple time in an inheritance tree called only once through super, as it is today's behavior, and is sometimes what we want. That's what i'm most unclear on, maybe we could have a class attribute, or a method decorator. Maybe we could add an argument to super, idk. The point would be to be able to specify somewhere the strategy we wanna use for parent appearing multiple times. maybe something like that would work fine: ``` import strat class HalfBreed(ProudGobelin, CorruptedGobelin): __visit_reoccuring_parents__ = strat.last def scream(self): ... (same as before) ``` or ``` import strat class HalfBreed(ProudGobelin, CorruptedGobelin): @visit_reoccuring_parents(strat.last) def scream(self): ... (same as before) ``` where available strats would be "last", "all", and maybe "only_after", where we would be able to specify which occurence should be visited. the decorator allows a method specific selection, the class attribute doesn't, so maybe the decorator is better. Idk, what do you think? Overall what matters to me is that we can chose the strat in case a parent appears multiple time in an inheritance tree, and that we can set the default strat to match today's strat. The implementation details, and overall API, i don't know exactly what they should look like.