Private attributes which are written but never read are a case of "dead store". Changing their value is useless and most probably indicates an error in the code.

Why is this an issue?

Python has no real private attribute. Every attribute is accessible. There are however two conventions indicating that an attribute is not meant to be "public":

This rule raises an issue when a class-private attribute (two leading underscores, max one underscore at the end) is never read inside the class. It optionally raises an issue on unread attributes prefixed with a single underscore. Both class attributes and instance attributes will raise an issue.

How to fix it

Remove the attribute or fix the code to read it.

Code examples

Noncompliant code example

class Noncompliant:
    _class_attr = 0  # Noncompliant if enable_single_underscore_issues is enabled
    __mangled_class_attr = 1  # Noncompliant

    def __init__(self, value):
        self._attr = 0  # Noncompliant if enable_single_underscore_issues is enabled
        self.__mangled_attr = 1  # Noncompliant

    def compute(self, x):
        return x * x

Compliant solution

class Compliant:
    _class_attr = 0
    __mangled_class_attr = 1

    def __init__(self, value):
        self._attr = 0
        self.__mangled_attr = 1

    def compute(self, x):
        return x * Compliant._class_attr * Compliant.__mangled_class_attr * self._attr * self.__mangled_attr

Resources

Documentation