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. The syntax for this is straightforward:

class MyClass(BaseClass1, BaseClass2):
    pass

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:

What is the potential impact?

This issue has minimal runtime impact since Python automatically removes duplicate base classes from the Method Resolution Order. However, it affects code quality:

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