Why is this an issue?

When a class field is defined multiple times in the same class body, only the last assignment takes effect. All previous assignments are dead code that serve no purpose.

This pattern typically occurs due to copy-paste errors, refactoring mistakes, merge conflicts, or misunderstanding of how class attributes work.

What is the potential impact?

How to fix it

Remove all but the last assignment to the class field.

Code examples

Noncompliant code example

class MyClass:
    x = 1
    y = 2
    x = 3  # Noncompliant: "x" is defined twice

Compliant solution

class MyClass:
    x = 3
    y = 2

Resources

Documentation