This rule raises an issue when the same class appears more than once in the inheritance list of a class definition.

Why is this an issue?

In Python, a class definition can inherit from one or more base classes. When the same base class appears multiple times in the inheritance list, it serves no purpose and is always a programming error. Python's Method Resolution Order (MRO) ensures that each class appears only once in the inheritance chain, even if it is listed multiple times.

This typically happens due to copy-paste errors, misunderstanding of inheritance, or refactoring mistakes.

How to fix it

Remove the duplicate base class from the inheritance list, keeping only one occurrence.

Code examples

Noncompliant code example

class MyWidget(QWidget, Serializable, QWidget):  # Noncompliant
    pass

Compliant solution

class MyWidget(QWidget, Serializable):
    pass

Resources

Documentation