What is the semantics meaning of 'object'?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Jun 26 19:54:38 EDT 2013


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.

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.


> 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.


-- 
Steven



More information about the Python-list mailing list