Wrong super() Arguments

ID

python.wrong_super_args

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

Python

Tags

reliability, suspicious-construct

Description

Reports calls to super(X, …​) where the first argument is not the enclosing class. The two-argument form of super requires the first argument to be the class whose MRO is being walked; passing the wrong class silently resolves to a different parent and produces hard-to-debug inheritance bugs.

class Foo(Bar):
    def __init__(self):
        super(Wrong, self).__init__()        # FLAW

    def reset(self):
        super().reset()                       # OK — zero-arg form

    def update(self):
        super(Foo, self).update()             # OK — explicit and correct

Rationale

The classic source of the bug is a copy-pasted method whose super(OldClass, self) was not updated when the method moved to a new class. Python does not validate the relationship between the argument and the enclosing class, so the call works at runtime — but resolves to whatever parent OldClass had, not what the new class needs.

Python 3 introduced the zero-argument super() form precisely to remove this footgun. New code should prefer it; the explicit form is needed only when calling super from outside a method body.

Remediation

Switch to super() (no arguments) inside a method body. If the explicit form is required, pass the enclosing class name as the first argument.

References