terrencepreilly / darglint

A python documentation linter which checks that the docstring description matches the definition.
MIT License
481 stars 41 forks source link

Raise of a function that produces an exception #164

Open xome4ok opened 3 years ago

xome4ok commented 3 years ago

If a result of a function, that returns exception is raised, darglint treats this function itself as an exception.

Consider the following example:

def raise_an_error() -> Exception:
    return Exception()

def some_function():
    """This is a function.

    :raises Exception: not what you expected
    """
    raise raise_an_error()

When I run darglint, I expect it to run without issues, but it insists that some_function raises not an Excpetion instance, but raise_an_error.

$ darglint .
darglint_bug.py:some_function:5: DAR401: -r raise_an_error

Reproduced on Python 3.9.2

$ pip freeze
darglint==1.7.0
mccabe==0.6.1
pycodestyle==2.7.0
pyflakes==2.3.1
pawamoy commented 3 years ago

Another example:

def validate(exception=MatrixError):
    """
    Validate something.

    Arguments:
        exception: The exception type.

    Raises:
        MatrixError: When the validation failed.
    """
    ...
    raise exception(message)

Missing exception(s) in Raises section: -r exception

This code might not be considered best-practice of course, but in some cases it's unavoidable :sweat_smile: