Skip to content

PY-INTE0002 · single_implementation_abstract_base

Count abstract bases that support only one repository implementation.

This is a deterministic rule for python. Read its implementation.

Build the repository inheritance graph and report a top-level Python class that explicitly derives from ABC or ABCMeta, or declares an abstract member, when exactly one descendant implements it. An abstract base adds indirection to let implementations vary. With only one implementation, the indirection has cost but no choice.

Each finding names the abstract base, its one descendant, and the complete declaration range. The value is the number of single-implementation abstract bases in the file.

Protocols are excluded because structural implementations need not inherit the protocol and a closed-world subclass graph cannot count them. An abstract base with two or more descendants has earned its variation point. A base with no descendants is owned by the separate unused declaration and abstraction reach rules.

Bad

An abstract `FactProvider` with only `DependencyProvider` below it returns `1`.
Good

An abstract Renderer implemented by JsonRenderer and TextRenderer returns 0.

  • Cites “The Python Standard Library”, abc
  • Cites “A Philosophy of Software Design”, deep modules and useful abstractions