[Python-Dev] Problems with the new super()
Georg Brandl
g.brandl at gmx.net
Thu May 1 20:20:41 CEST 2008
Armin Ronacher schrieb:
>> The super() thing is a case of practicality beats purity. Note that
>> you pay a small but measurable cost for the implicit __class__ (it's
>> implemented as a "cell variable", the same mechanism used for nested
>> scopes) so we wouldn't want to introduce it unless it is used.
> I do agree that super() is a lot easier to work with than regular way to
> call it. But the fact that it breaks if i do `_super = super` or that
> it's impossible to emulate it from within Python.
That it isn't emulatable from Python doesn't bother me -- several functions
have that property.
But the other two magical things about super() really bother me too. I
haven't looked at the new super in detail so far (and I don't know how
many others have), and two things are really strikingly unpythonic in
my view:
* super() only works when named "super" [1]. It shouldn't be a function if
it has that property; no other Python function has that.
* "__class__" is magical in classes. If you define a local called "__class__"
super won't work anymore in that function.
Also, you can access "__class__" from any method, without the "self."
qualifier -- another magical name.
There may be more implications and surprising behavior surrounding this.
I know that the implementation is a compromise, but I'd rather see a super()
whose full semantics can be explained to programmers without using to
"cell variable", "f_localsplus" and "symtable".
cheers,
Georg
[1] Actually, it only works if a name "super" is accessed somewhere in the
function, but this is what someone trying to alias "super" will perceive.
--
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.
More information about the Python-Dev
mailing list