This rule raises an issue when the same class appears more than once in the inheritance list of a class definition.
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:
This issue has minimal runtime impact since Python automatically removes duplicate base classes from the Method Resolution Order. However, it affects code quality:
Remove the duplicate base class from the inheritance list, keeping only one occurrence.
class MyWidget(QWidget, Serializable, QWidget): # Noncompliant
pass
class MyWidget(QWidget, Serializable):
pass