Skip to content

PY-CLAS0007 · hazardous_multiple_inheritance_mro_count

Count deterministic MRO hazards among project-owned direct bases.

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

Build the project inheritance graph and inspect undecorated classes with at least two resolved project-owned direct bases. Report a class when one direct base already inherits another, or when several direct bases provide the same concrete method and at least one implementation does not delegate that same method through zero-argument super(). Abstract methods, overloads, ellipsis or pass stubs, and NotImplementedError placeholders do not create a collision. Disjoint or fully cooperative mixins remain accepted.

Each finding records base order, concrete colliding method owners, redundant ancestor edges, and the complete subclass range. Measurements expose the number of project bases, collisions, and precedence edges separately. The value is the number of classes carrying a proven order-sensitive hierarchy.

External bases are not guessed. Decorated classes and classes with metaclass or other keywords are excluded because frameworks can define their own linearization contract. A collision is accepted when every direct implementation explicitly participates in cooperative dispatch. Composition may still be preferable, but this rule reports only proven order sensitivity.

class JsonLoader:
def load(self) -> bytes:
return b"json"
class CachedLoader:
def load(self) -> bytes:
return b"cache"
class Service(JsonLoader, CachedLoader):
pass
class Specialized(Base, BaseContract):
pass
class TimestampMixin:
def timestamp(self) -> float:
return time.time()
class NamedMixin:
def name(self) -> str:
return type(self).__name__
class Record(TimestampMixin, NamedMixin):
pass
  • Generalizes Pylint R0901 too-many-ancestors
  • Cites “Python HOWTOs”, method resolution order. Open reference
  • Cites “The Python Standard Library”, zero-argument super. Open reference
  • Cites “Python’s super() Considered Super”. Open reference