When initializing an instance of the class in the class' __init__ method, calls tha are made using the instance may receive an instance of the class that is not yet fully initialized. When a method called in an initializer is overridden in a subclass, the subclass method receives the instance in a potentially unexpected state, which may lead to runtime errors from accessing uninitialized fields, and generally makes the code more difficult to maintain.

If possible, refactor the initializer method such that initialization is complete before calling any overridden methods. For helper methods used as part of initialization, avoid overriding them, and instead call any additional logic required in the subclass' __init__ method.

If calling an overridden method is required, consider marking it as an internal method (by using an _ prefix) to discourage external users of the library from overriding it and observing partially initialized state.

In the following case, the `__init__` method of `Super` calls the `set_up` method that is overriden by `Sub`. This results in `Sun.set_up` being called with a partially initialized instance of `Super` which may be unexpected.

In the following case, the initialization methods are separate between the superclass and the subclass.

  • CERT Secure Coding: Rule MET05-J. Reference discusses Java but is applicable to object oriented programming in many languages.
  • StackOverflow: Overridable method calls in constructors.