Python, unlike some other object-oriented languages such as Java, allows the developer complete freedom in when and how superclass initializers are called during object initialization. However, the developer has responsibility for ensuring that objects are properly initialized, and that all superclass __init__ methods are called.

If the __init__ method of a superclass is not called during object initialization, this can lead to errors due to the object not being fully initialized, such as having missing attributes.

A call to the __init__ method of a superclass during object initialization may be unintentionally skipped:

Ensure that all superclass __init__ methods are properly called. Either each base class's initialize method should be explicitly called, or super() calls should be consistently used throughout the inheritance hierarchy.

In the following example, explicit calls to __init__ are used, but SportsCar erroneously calls Vehicle.__init__. This is fixed in FixedSportsCar by calling Car.__init__.

  • Python Reference: __init__.
  • Python Standard Library: super.
  • Python Glossary: Method resolution order.