Skip to content

docstring-missing-returns (DOC201) reports on explicit None returns in bodies that return None only #13062

@tjkuson

Description

@tjkuson

Running ruff check --select DOC201 --preview --isolated on

def foo(obj: object) -> None:
    """A very helpful description."""
    if obj is None:
        return None
    print(obj)

reports a docstring-missing-returns (DOC201) diagnostic. Making the None return implicit means the diagnostic is raised no longer.

def foo(obj: object) -> None:
    """A very helpful description."""
    if obj is None:
        return
    print(obj)

The expected behaviour is that the diagnostic is raised in neither situation, as the function returns None on all paths and the explicit return operates as an early exit.

I don't like the explicit None return and unnecessary-return-none (RET501) would catch this, but it still seems like the incorrect behaviour for this specific rule.

Reproduced on Ruff version 0.6.1.

Search terms: DOC201, docstring-missing-returns

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedReady for implementationdocstringRelated to docstring linting or formatting

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions