On 06/26/2013 04:54 PM, Steven D'Aprano wrote:
On Wed, 26 Jun 2013 13:14:44 -0700, Ethan Furman wrote:

On 06/23/2013 11:50 AM, Steven D'Aprano wrote:

What else would you call a function that does lookups on the current
object's superclasses?

Well, I would call it super().  Trouble is, that is not all that super()
does.  Going back to Ian's example:

On 06/23/2013 10:08 AM, Ian Kelly wrote:

class Base1(object):
     def __init__(self, foo, **kwargs):
        super(Base1, self).__init__(**kwargs)

class Base2(object):
     def __init__(self, bar, **kwargs):
        super(Base2, self).__init__(**kwargs)

class Derived(Base1, Base2):
     def __init__(self, **kwargs):
        super(Derived, self).__init__(**kwargs)

Notice how Base1 calls super(), but depending on circumstances, it could
by Base2 that super() calls.  Surely you are not suggesting that Base2
is therefore an ancestor of Base1?

No. But "the current object" is not Base1, but an instance of Derived,
and Base2 *is* an ancestor of Derived. Perhaps if I had said "self"
instead of current object, you wouldn't have made this error. If so, I
apologise for confusing you.

No apology necessary.  I understand both inheritance and super fairly well, and 
you did not confuse me.


When your inheritance chain begins from an instance of Base1, Base2
methods will never be called. It is only when the chain begins from
Derived that Base2 may be called, which is exactly as it should be.

Absolutely. That doesn't change the fact that when writing Base1 you are still using the word 'super', and hopefully remembering that even though it's named 'super' it may in fact call an object that is sideways from where you're at now and have absolutely no relation to Base1's ancestors.


It's too late to change the name now, but pretending there is no good
and valid reason for confusion doesn't help.

The confusion is not with the name, or what super does, but with
inheritance itself.

Good names are important because a good name can help alleviate confusion. A bad name can exacerbate it. Given the terminology of superclasses and subclasses, naming a function 'super' that can in fact call another class that is in no way the superclass of the class in which it is written, can easily cause confusion.

--
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to