This rule raises an issue when a private nested class is never used.

Why is this an issue?

"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.

Code examples

Noncompliant code example

class TopLevel:
    class __Nested():  # Noncompliant: __Nested is never used
        pass

Compliant solution

class TopLevel:
    class __Nested():
        pass

    def process(self):
        return TopLevel.__Nested()

Resources