Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tjkuson opened this issue Aug 22, 2024 · 0 comments · Fixed by #13064
Labels
accepted Ready for implementation docstring Related to docstring linting or formatting

Comments

@tjkuson
Copy link
Contributor

tjkuson commented Aug 22, 2024

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

@AlexWaygood AlexWaygood added docstring Related to docstring linting or formatting accepted Ready for implementation labels Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Ready for implementation docstring Related to docstring linting or formatting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants