Skip to content

missing-return-type

Part of: Enrichment Check

Check enrichment
Category recommended
Applies to functions, methods
Since v1.14.0

Returns section has no type and function has no return annotation

What it detects

This rule flags functions and methods that document a return value (for example, a Google-style Returns: section or a Sphinx-style :returns:/:rtype: pair) but have no type information — neither a typed entry in the docstring (e.g., dict: The result. or :rtype: dict) nor a -> return annotation on the function signature.

Why is this a problem?

Without a documented return type, callers must read the implementation to determine what the function returns. API documentation generated by mkdocstrings will lack return type information, and IDE tooling cannot provide accurate type hints.

Either a typed Google-style Returns: entry, a Sphinx-style :rtype: directive, or a return annotation satisfies this check — all convey the return type to readers and tools.

How to Fix

Add a type to the Returns: entry:

Returns:
    dict: The parsed configuration as a dictionary.

Or add a return annotation to the function signature:

def parse_config(path: str) -> dict:

Either approach is sufficient — you don't need both.

Example

def find_user(user_id: int):
    """Look up a user by ID.

    Args:
        user_id: The user's numeric identifier.

    Returns:
        The matched user, or None if no match is found.
    """
    return db.query(User).get(user_id)
def find_user(user_id: int):
    """Look up a user by ID.

    Args:
        user_id: The user's numeric identifier.

    Returns:
        User | None: The matched user, or None if no match is found.
    """
    return db.query(User).get(user_id)
def find_user(user_id: int) -> User | None:
    """Look up a user by ID.

    Args:
        user_id: The user's numeric identifier.

    Returns:
        The matched user, or None if no match is found.
    """
    return db.query(User).get(user_id)

Exceptions

This rule is automatically skipped for:

  • __init__ and __del__ methods (constructors/destructors)
  • @property and @cached_property methods
  • Functions without a Returns: section (handled by missing-returns instead)
  • NumPy-style underline Returns sections (content extraction not yet supported)