Skip to content

yield-type-required (PDF709)

Added in 1.0.0 Never fix Convention-explicit

Part of the PDF rule category.

View source · View documentation source · Search issues

Fix is not available.

Rule is disabled if docstring-convention is none or pep257, and ignored by broad selectors under google, numpy, and rest.

Rule is incompatible with PDF710.

What it does

Checks that parsed yield entries in owning function docstrings include a documented type.

Only functions that actually contain yield expressions are checked. The rule is exact opt-in because many projects rely on generator annotations instead of repeating yield types in docstrings.

Why is this useful?

Projects that keep yield types in docstrings can enforce complete yield type documentation.

Ruff compatibility

None.

Examples

PDF709 reports yield entries without docstring types:

docstring-convention = "rest"
def function() -> Iterator[int]:
    """Yield values.

    :yields: Next value.
    """
    yield 1
PDF709: Line 4: Function yield 'yield' docstring entry is missing a type

Yield entries with types are accepted:

docstring-convention = "google"
def function() -> Iterator[int]:
    """Yield values.

    Yields:
        int: Next value.
    """
    yield 1

reST :ytype: fields provide the type for paired yield documentation:

docstring-convention = "rest"
def function() -> Iterator[int]:
    """Yield values.

    :yields: Next value.
    :ytype: int
    """
    yield 1

Options

None.