This rule raises an issue when the same class field is unconditionally assigned multiple times within a class body.

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:

What is the potential impact?

How to fix it

Remove all but the last assignment to the class field. Keep only the final value that should be used.

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

Related rules