Skip to content

yield-type-forbidden (PDF710)

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 PDF709 and PDF711.

What it does

Checks that parsed yield entries in owning function docstrings do not include documented types.

Only functions that actually contain yield expressions are checked. The rule is exact opt-in and cannot be combined with the required-type or type-mismatch yield policies.

Why is this useful?

Projects that rely on code annotations can prevent duplicated yield type documentation.

Ruff compatibility

None.

Examples

PDF710 reports yield entries that include docstring type text:

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

    Yields:
        int: Next value.
    """
    yield 1
PDF710: Line 5: Function yield 'yield' docstring entry should not include a type

Yield entries without types are accepted:

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

    :yields: Next value.
    """
    yield 1

reST :ytype: fields are also forbidden because they provide docstring type text:

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

    :yields: Next value.
    :ytype: int
    """
    yield 1
PDF710: Line 5: Function yield 'yield' docstring entry should not include a type

Options

None.