terrencepreilly / darglint

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

Darglint reports error when an exception is raised with `.with_traceback(...)` #181

Open gschwaer opened 2 years ago

gschwaer commented 2 years ago

The following code generates two darglint errors:

def traceback_test(self):
        """[summary]

        Raises:
            ValueError: [description]
        """
        try:
            print("")
        except BaseError as e:
            raise ValueError("...").with_traceback(e.__traceback__)

Observed Behavior

test.py:traceback_test:42: DAR401: -r with_traceback
test.py:traceback_test:46: DAR402: +r ValueError

It seems darglint does not know of the with_traceback() function.

Expected Behavior

In this case no error at all.

with_traceback should be interpreted as if it wasn't there because it returns the same exception object.

leandro-lucarella-frequenz commented 1 year ago

This extends to any raise that is not purely instantiating a class (or probably calling a function in general). For example:

def test(self):
        """[summary]

        Raises:
            ValueError: [description]
        """
        try:
            print("")
        except ValueError as e:
            # Do something with e
            raise e

Will also produce a bogus:

test.py:traceback_test:42: DAR401: -r e
test.py:traceback_test:46: DAR402: +r ValueError
leandro-lucarella-frequenz commented 1 year ago

BTW, this can be workaround by using a noqa:

def test(self):
        """[summary]

        Raises:
            ValueError: [description]

        # noqa: DAR401 e
        """
        try:
            print("")
        except ValueError as e:
            # Do something with e
            raise e

Or with_traceback instead of e in the original example.