On 4/04/22 10:46 pm, Steven D'Aprano wrote:
Now tell me that
before you ran the code, or read my analysis of it, you would have
predicted that super(ProudGobelin, self) would skip ProudGobelin's
method and call CorruptedGobelin's method.

I could have told you that it would skip ProudGobelin, because
that's what super does. It starts looking in the MRO *after* the
class you pass it, never in that class itself.

It does this because the way it's intended to be used is to
pass it the class in which the method you're calling it from is
defined. It's designed that way because originally there was no
other way for it to tell where to start searching. Now that
we have argumentless super, there's no longer any need to do
that.

As for telling which method it *would* call, I could probably
figure it out for a simple inheritance hierarchy like this.

I could certainly have told you that ProudGobelin's method
would be called at *some* point in the chain after HalfBreed's,
because ProudGobelin appears above HalfBreed in the inheritance
hierarchy.

I would say that's all you should *need* to know. If you're
using super at all with MI, your methods should all be designed
so that it *doesn't matter* exactly what order they get called in,
other than the fact that methods further up the hierarchy are
called after methods further down.

If that's not the case, then super is the wrong tool for the job.

I would also say that if you're passing super anything *other*
than the class where the method is defined, you're trying to
be too clever by half, and will get bitten.

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

Reply via email to