super() doesn't get superclass
Neil Cerutti
horpner at yahoo.com
Wed Sep 19 08:58:48 EDT 2007
On 2007-09-19, Hrvoje Niksic <hniksic at xemacs.org> wrote:
> Ben Finney <bignose+hates-spam at benfinney.id.au> writes:
>
>> Hrvoje Niksic <hniksic at xemacs.org> writes:
>>
>>> class X(Y):
>>> def foo(self):
>>> super(X, self).foo()
>>>
>>> ...there is in fact no guarantee that super() calls a superclass of
>>> X. However, it is certainly guaranteed that it will call a superclass
>>> of type(self).
>>
>> Not even that. It could call *any class in the inheritance
>> hierarchy*,
>
> The inheritance hierarchiy is populated by the various (direct
> and indirect) superclasses of type(self).
>
>> depending on how the MRO has resolved "next class". Even one that is
>> neither an ancestor nor a descendant of X.
>
> My point exactly. superclass of X is not the same as
> superclass of type(self). Super iterates over the latter,
> where you expect the former.
I can't blame a person for thinking that the call
super(A, self)
is taking the superclass of A. A is perhaps too prominently
placed.
--
Neil Cerutti
More information about the Python-list
mailing list