super() doesn't get superclass

Ben Finney bignose+hates-spam at benfinney.id.au
Tue Sep 18 19:14:15 EDT 2007


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*,
depending on how the MRO has resolved "next class". Even one that is
neither an ancestor nor a descendant of X.

-- 
 \     "When I was a kid I used to pray every night for a new bicycle. |
  `\    Then I realised that the Lord doesn't work that way so I stole |
_o__)                one and asked Him to forgive me."  -- Emo Philips |
Ben Finney



More information about the Python-list mailing list