"Private" nested classes that are never used inside the enclosing class are usually dead code: unnecessary, inoperative code that should be removed. Cleaning out dead code decreases the size of the maintained codebase, making it easier to understand the program and preventing bugs from being introduced.

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

This rule raises an issue when a private nested class (either with one or two leading underscores) is never used inside its parent class.

Noncompliant Code Example

class Noncompliant:
    class __MyClass1():  # Noncompliant
        pass

    class _MyClass2():  # Noncompliant
        pass

Compliant Solution

class Compliant:
    class __MyClass1():
        pass

    class _MyClass2():
        pass

    def process(self):
        return Compliant.__MyClass1()

    def process(self):
        return Compliant._MyClass2()

See