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

Extend docstring-missing-exception to empty exception description (DOC501) #14494

Open
sbrugman opened this issue Nov 20, 2024 · 3 comments · May be fixed by #14496
Open

Extend docstring-missing-exception to empty exception description (DOC501) #14494

sbrugman opened this issue Nov 20, 2024 · 3 comments · May be fixed by #14496
Labels
docstring Related to docstring linting or formatting rule Implementing or modifying a lint rule

Comments

@sbrugman
Copy link
Contributor

sbrugman commented Nov 20, 2024

The rule that checks missing documentation for parameters considers empty descriptions as undocumented (undocumented-param, DOC501).
We have a similar rule for exceptions, which considers empty descriptions as documented (docstring-missing-exception, D417).

This example only errors for DOC501:

def func1(arg1: str, arg2: int) -> int:
    """

    Args:
        arg1:
        arg2:

    Raises:
        ValueError:
    """
    try:
        return int(arg1) + arg2
    except:
        raise ValueError("msg")
 ruff check --select D417,DOC501 --preview example.py

Proposal: modify D417 to report an error for empty exception descriptions.

Alternative solution: split undocumented and empty/missing into two separate rules.

This behaviour is especially useful when docstring stubs are auto-generated (#14492)

@AlexWaygood AlexWaygood added rule Implementing or modifying a lint rule docstring Related to docstring linting or formatting labels Nov 20, 2024
@jsh9
Copy link

jsh9 commented Jan 13, 2025

Hi,

I'm the author of pydoclint.

Just FYI, in pydoclint version 0.6.0 (the current latest version), this code example generates no violations:

def func1(arg1: str, arg2: int) -> int:
    """

    Args:
        arg1:
        arg2:

    Returns:
        int:

    Raises:
        ValueError:
    """
    try:
        return int(arg1) + arg2
    except:
        raise ValueError("msg")

(It has a "Returns" section in the docstring)

Here are the pydoclint config options I used:

  • style: google
  • argTypeHintsInDocstring: False
  • skipCheckingRaises: False

So this may have been a bug only in Ruff and not in pydoclint.

@MichaReiser
Copy link
Member

There's some precedence for empty docstring rules, e.g. https://docs.astral.sh/ruff/rules/empty-docstring-section/ and https://docs.astral.sh/ruff/rules/empty-docstring/

@brendan-m-murphy
Copy link

Not really a bug, but if you omit the colon after ValueError and write something like

Raises:
    ValueError some description

then the error message is the same as if you didn't have a Raises: section at all. It would be helpful if it just said you need to add a colon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docstring Related to docstring linting or formatting rule Implementing or modifying a lint rule
Projects
None yet
5 participants