[Python-Dev] Problem with super() usage

Scott Dial scott+python-dev at scottdial.com
Tue Jul 18 15:10:11 CEST 2006


Greg Ewing wrote:
> Guido van Rossum wrote:
>> In the world where cooperative multiple inheritance
>> originated (C++), this would be a static error.
> 
> I wasn't aware that C++ had anything resembling super().
> Is it a recent addition to the language?
> 

It is much more explicit, but you call the function from the 
superclass's namespace:

class B : public A {
public:
   void m(void) {
     A::m(); // The call to my super
   };
};

C++ has no concept of MRO, so "super()" would be completely ambiguous. 
In fact, if you try to replicate your code in C++ using a generic M 
class (which defines a dummy m method), you'll get such an error from 
your compiler: "`M' is an ambiguous base of `C'"

This is very much a dynamic language quirk that you can call out to a 
function that may or may not exist, and we should avoid comparing it to 
other languages which don't allow it. I agree with Guido that in python, 
the reasonable fix is to have a superclass which defines an empty method.

-- 
Scott Dial
scott at scottdial.com
scodial at indiana.edu


More information about the Python-Dev mailing list