B
Ben Finney
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.
Can anyone point me to a counter-argument to the above article?
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.
Can anyone point me to a counter-argument to the above article?