On Sep 18, 12:15 am, Ben Finney <[EMAIL PROTECTED]> wrote: > Howdy all, > > After banging my head against super() trying to reliably get > attributes of a superclass, I gained a little enlightenment when this > turned up in a search: > > "Python's Super is nifty, but you can't use it > (Previously: Python's Super Considered Harmful)" > <URL:http://fuhm.org/super-harmful/> > > An early paragraph stood out that made my current problems clear: > > One big problem with 'super' is that it sounds like it will cause > the superclass's copy of the method to be called. This is simply > not the case, it causes the next method in the MRO to be called. > > Oh. The author's right, I got that mistaken impression too. Obviously, > then, I must have misread the documentation of 'super'. I went back to > double-check, and was appalled to find: > > super(type[, object-or-type]) > Return the superclass of type. [...] > > <URL:http://docs.python.org/lib/built-in-funcs.html#l2h-72> > > Why does the documentation of 'super' say that it returns the > superclass when *that's not true*? It doesn't return the superclass, > it returns the next class in the MRO, whether that's a superclass or > not. > > Actually, even that's not true. The error message "AttributeError: > 'super' object has no attribute 'bazfunc'" makes it clear that 'super' > actually returns not the superclass, but a 'super' object, whatever > that's supposed to be. > > After reading the rest of the article, I'm amazed that 'super' as > currently implemented is in Python at all. I agree with the author > that it's useless unless *everyone* uses it for *everything*, and even > then it's pretty limited. > > One thing's for sure, it's badly misnamed, and falsely documented.
You are right, I think I even filed a documentation bug for that years ago, and I wrote an entire paper on the subject that however I never published since I never felt 100% confident with super (and I had other fishes to fry ;) I realize now that I was wrong in not publishing it. You can find the draft (warning: it is a draft, I did not check the examples there, they are likely broken) here: http://www.phyast.pitt.edu/~micheles/python/super.html It begins as follows: """ The truth about super Author: Michele Simionato Date: June 2004 Status: Draft super is a new built-in, first introduced in Python 2.2 and slightly improved and fixed in Python 2.3, which is little known to the average Python programmer. One of the reason for this fact is its poor documentation`: at the time of this writing (June 2004) super documentation is incomplete and in some parts misleading and even wrong. For instance, it was recently pointed out on comp.lang.python that the standard library (Python 2.3.4, section 2.1) still says: super(type[, object-or-type]) Return the superclass of type. If the second argument is omitted the super object returned is unbound. If the second argument is an object, isinstance(obj, type) must be true. If the second argument is a type, issubclass(type2, type) must be true. super() only works for new- style classes. The first sentence is just plain wrong. super does not return the superclass. There is no such a thing as "the" superclass in a Multiple Inheritance (MI) language. Also, the sentence about 'unbound' is misleading, since it may easily lead the programmer to think about bound and unbound methods, whereas it has nothing to do with that concept. Finally, there subtle pitfalls of super which are not at all mentioned. IMNSHO super is one of the most trickiest and surprising Python constructs, so it absolutely needs a document to share light on some of his secrets: the present article aims to fix the issues with the current documentation, and tell you the "truth" about super. At least the amount of truth I have discovered with my experimentations, which is certainly not the whole truth ;) Here is the plan: first I will discuss the concept of superclass in a Multiple Inheritance (MI) world (there is no such a thing as "the" superclass!); second, I will show that super is a proxy object, able to dispatch to the right methods/attributes in the MRO; third, recall some background on how the resolution of methods works on how descriptors work and (essentially pointing out to the standard references); then I will discuss the more common invocation of super - the invocation with two arguments - and finally I will discuss the most tricky part, i.e. invoking super with just one argument and I will discuss pitfalls. Finally, a fair warning: this document is aimed to expert Pythonistas. It is not for the faint of heart ;) """ -- http://mail.python.org/mailman/listinfo/python-list