Skip to content

missing-private-dunder-method-documentation (PDF613)

Added in 1.0.0 Never fix Requires explicit

Part of the PDF rule category.

View source · View documentation source · Search issues

Fix is not available.

Rule must by default be explicitly selected, unless it is removed from require-explicit.

What it does

Checks for private dunder methods that are missing docstrings.

A dunder method is private when its containing class or package/module path is private. The rule excludes __init__, which is handled by PDF614 and PDF615.

Why is this useful?

Private dunder methods can still benefit from local documentation when a project chooses to require it.

Ruff compatibility

None.

Examples

A dunder method on a private class is reported as private:

class _Client:
    """Client."""

    def __str__(self):
        return "client"
PDF613: Line 4: Private dunder method '_Client.__str__' is missing docstring

A dunder method in a private module path is also private:

class Client:
    """Client."""

    def __str__(self):
        return "client"
PDF613: Line 4: Private dunder method 'Client.__str__' is missing docstring

__init__ is intentionally excluded:

class _Client:
    """Client."""

    def __init__(self):
        pass

A documented private dunder method is accepted:

class _Client:
    """Client."""

    def __str__(self):
        """Return the display name."""
        return "client"

Public dunder methods are handled by PDF612 instead:

class Client:
    """Client."""

    def __str__(self):
        return "client"

Options