Skip to content

section-name-trailing-colon (PDF404)

Added in 1.1.0 Usually fix Convention Module and Fragment

Part of the PDF rule category.

View source · View documentation source · Search issues

Fix is usually available.

Rule is disabled if docstring-convention is none, pep257, numpy, or rest.

What it does

PDF404 reports recognized Google section names that are missing the required trailing colon. The fix adds one colon immediately after the section name and removes only ASCII spaces or tabs at the outer boundary of the remaining suffix. Other whitespace and controls are preserved with their existing source spelling for PDF004 or other authoritative rules.

The fix is available for safely mapped simple docstrings. Concatenated docstrings and source mappings that cannot be safely rewritten are reported without a fix.

Why is this useful?

The colon is part of Google-style section header spelling and helps distinguish headers from ordinary prose.

Ruff compatibility

This rule is intended to replace Ruff's D416.

Examples

PDF404 adds a missing Google section-name colon:

docstring-convention = "google"
def value(arg):
    """Return the value.

    Args
        arg: The value.
    """
def value(arg):
    """Return the value.

    Args:
        arg: The value.
    """

Multiple missing colons in one docstring are fixed together, and trailing spaces or tabs after the section name are removed:

docstring-convention = "google"
def value(arg):
    """Return the value.

    Args
        arg: The value.

    Returns 
        int: The value.
    """
def value(arg):
    """Return the value.

    Args:
        arg: The value.

    Returns:
        int: The value.
    """

PDF404 does not capitalize section names while adding the colon. That is handled by PDF400:

docstring-convention = "google"
def value(arg):
    """Return the value.

    args
        arg: The value.
    """
def value(arg):
    """Return the value.

    args:
        arg: The value.
    """

Already-colonized section names are left to whitespace rules, even if trailing whitespace remains on the line:

docstring-convention = "google"
def value(arg):
    """Return the value.

    Args:   
        arg: The value.
    """

PDF404 only applies to Google sections. NumPy-style section names do not require a trailing colon:

docstring-convention = "numpy"
def value(arg):
    """Return the value.

    Parameters
    ----------
    arg : int
        The value.
    """

Concatenated docstrings are reported when a missing Google section colon can be parsed, but they are not safely rewritten:

docstring-convention = "google"
def value(arg):
    ("Return the value.\n\n"
     "Args\n"
     "    arg: The value.")
PDF404: Lines 2-4: Docstring section 'Args' should end with a colon

Options

None.