"Super()" confusion

Jean-Paul Calderone exarkun at divmod.com
Mon Feb 9 19:31:37 EST 2009


On Mon, 9 Feb 2009 16:18:34 -0800 (PST), Lionel <lionel.keene at gmail.com> wrote:
>On Feb 9, 4:04 pm, Jean-Paul Calderone <exar... at divmod.com> wrote:
>> On Mon, 9 Feb 2009 15:20:05 -0800 (PST), Lionel <lionel.ke... at gmail.com> wrote:
>> >Hello. I've been scouring the web looking for something to clear up a
>> >little confusion about the use of "super()" but haven't found anything
>> >that really helps. Here's my simple example:
>>
>> > [snip]
>>
>> >"super(Child,self).__init__(filePath)
>> >TypeError: super() argument 1 must be type, not classobj"
>>
>> >What have I done wrong? Thanks in advance for any help.
>>
>> Consider whether you really need to use super().
>>
>> http://fuhm.net/super-harmful/
>>
>> Jean-Paul
>
>Yes, I came across that essay...and it scared me. Will my base class
>initializer always get called regardless of whether or not I use super
>()? If so, does this occur prior to any code in my derived class
>initializer being executed (in other words, if I don't explicitly call
>"super()" in my derived class, am I guaranteed that the base class
>"__init__" has executed completely)? If so, then I guess I can forego
>the use of "super()"

Neither the use nor disuse of super can guarantee any of these things.
Old-style base method calling (ie, "Foo.bar(self, ...)" - as opposed to
using super) is just as capable of causing these things to happen as is
super *except* in the case of diamond inheritance.  If you use either
correctly, it will do what you want.  It's just that using super correctly
is a lot harder most of the time.

Jean-Paul



More information about the Python-list mailing list