Skip to content

[pydoclint] DOC502 should detect re-raised exceptions #12630

@edgarrmondragon

Description

@edgarrmondragon

Consider

# repro_DOC.py

def my_func(arg: int) -> int:
    """Doer of things.

    Args:
        arg (int): The number to be doubled.

    Returns:
        int: The doubled number.

    Raises:
        TypeError: If arg cannot be multiplied by 2.
    """
    try:
        return arg * 2
    except TypeError:
        print("arg should be an integer")
        raise

pydoclint correctly detects the exception is re-reraised:

$ pydoclint --style=google repro_DOC.py
Loading config from user-specified .toml file: pyproject.toml
No config found in pyproject.toml.
Skipping files that match this pattern: \.git|\.tox
repro_DOC.py
🎉 No violations 🎉

Ruff does not

$ ruff check --select DOC repro_DOC.py
repro_DOC.py:12:1: DOC502 Raised exception is not explicitly raised: `TypeError`
   |
 7 |           arg (int): The number to be doubled.
 8 |   
 9 | /     Raises:
10 | |         TypeError: If arg cannot be multiplied by 2.
11 | |     """
   | |____^ DOC502
12 |       try:
13 |           return arg * 2
   |

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingdocstringRelated 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