Skip to content

docstring-extraneous-returns (DOC202)

Derived from the pydoclint linter.

This rule is unstable and in preview. The --preview flag is required for use.

What it does

Checks for function docstrings that have a "returns" section without needing one.

Why is this bad?

Functions without an explicit return should not have a returns section in their docstrings.

This rule is not enforced for stub functions.

Example

def say_hello(n: int) -> None:
    """Says hello to the user.

    Args:
        n: Number of times to say hello.

    Returns:
        Doesn't return anything.
    """
    for _ in range(n):
        print("Hello!")

Use instead:

def say_hello(n: int) -> None:
    """Says hello to the user.

    Args:
        n: Number of times to say hello.
    """
    for _ in range(n):
        print("Hello!")