"Super()" confusion

Jean-Paul Calderone exarkun at divmod.com
Mon Feb 9 20:59:36 EST 2009

On Mon, 9 Feb 2009 17:34:05 -0800, Daniel Fetchinson <fetchinson at googlemail.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]
>>>>>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/
>>>Did you actually read that article, understood it, went through the
>>>tons of responses from python-dev team members, including Guido
>> Yes.  Why the knee-jerk reaction?
>Because throwing around that link carries about the same amount of
>information as "perl is better than python", "my IDE is better than
>yours", "vim rulez!", "emacs is cooler than vim", etc, etc.

That's not true.  The page contains lots of information.

>> I simply pointed out a resource which
>> might be helpful to someone trying to learn to use super.
>It will certainly not be helpful to anyone trying to learn the usage
>of super. The person who wrote that essay is simply misunderstanding
>the concept, as has been explained countless times by the python dev
>team. Hence, it only increases confusion, adds to the noise and
>spreads false alarm.

Quoting Guido, in whom you seem to place a lot of faith:

  Super is intended for use that are designed with method cooperation in
  mind, so I agree with the best practices in James's Conclusion:

    * Use it consistently, and document that you use it,
      as it is part of the external interface for your class, like it or not.
    * Never call super with anything but the exact arguments you received,
      unless you really know what you're doing.
    * When you use it on methods whose acceptable arguments can be
      altered on a subclass via addition of more optional arguments,
      always accept *args, **kw, and call super like
      "super(MyClass, self).currentmethod(alltheargsideclared, *args,
      If you don't do this, forbid addition of optional arguments in subclasses.
    * Never use positional arguments in __init__ or __new__.
      Always use keyword args, and always call them as keywords,
      and always pass all keywords on to super.

The original poster's code did not use it consistently, did not document its use, and used positional arguments in __init__.  So according to Guido, the
OP was misusing super.  Why are you complaining that I pointed this out?

>Honestly, I don't understand how this thing got so much out of
>control. If anyone starts an intelligent question or remark about
>super, this essay is thrown in no matter what. Anyone can explain why?

You're seriously overreacting.


More information about the Python-list mailing list