bad-super-call / E1003#

Message emitted:

Bad first argument %r given to super()

Description:

Used when another argument than the current class is given as first argument of the super builtin.

Correct code:

class Animal:
    pass


class Tree:
    pass


class Cat(Animal):
    def __init__(self):
        super(Animal, self).__init__()

Problematic code:

class Animal:
    pass


class Tree:
    pass


class Cat(Animal):
    def __init__(self):
        super(Tree, self).__init__()  # [bad-super-call]
        super(Animal, self).__init__()

Additional details:

In Python 2.7, super() has to be called with its own class and self as arguments (super(Cat, self)), which can lead to a mix up of parent and child class in the code.

In Python 3 the recommended way is to call super() without arguments (see also super-with-arguments).

One exception is calling super() on a non-direct parent class. This can be used to get a method other than the default method returned by the mro().

Related links:

Created by the newstyle checker.