Skip to content

ALL-OVER0006 · subclass_initializer_skips_its_base

Count subclasses that write their own initializer and never run the one above them.

This is a deterministic rule for all languages. Read its implementation.

Report a direct base that declares an initializer where the subclass declares one too and reaches neither super nor that base from inside it. Half a constructor ran, so the object exists and every attribute the base was going to set is simply missing. The first read of one raises an attribute error somewhere unrelated, and the reader who lands there has no reason to suspect a constructor, which is why this costs an afternoon rather than a minute.

Finding the skipped initializer means resolving the base across the repository and then reading what the subclass initializer actually calls. Both halves live in the graph, and neither is visible from the subclass alone.

Each finding names the subclass, the base whose initializer never ran, and the receivers the subclass initializer did call. The value is one for each base left unrun.

Only a direct base is judged, because an initializer that calls super hands the rest of the chain to Python and a class further up is not the subclass’s to call. A base whose initializer is marked abstract has nothing to run. A subclass with no initializer of its own inherits the base one intact and is not judged at all.

A base that runs its setup somewhere other than an initializer is a design MCMR cannot see, and a project built that way turns this rule off rather than adding empty calls. Pylint also skips an initializer marked as a typing overload and a base that is a protocol, and neither exemption is read here.

class Connection:
def __init__(self):
self.socket = open_socket()
class PooledConnection(Connection):
def __init__(self):
self.pool = []
class PooledConnection(Connection):
def __init__(self):
super().__init__()
self.pool = []
  • Generalizes Pylint W0231 super-init-not-called. Open reference
  • Cites “Python’s super() Considered Super”, PyCon 2015. Open reference
  • Cites “The Python Language Reference”, the method resolution order