terrencepreilly / darglint

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

False positive for raise in numpy doc #113

Closed steven-murray closed 4 years ago

steven-murray commented 4 years ago

Here's my method definition:

    @cached_property
    def n_terms(self):
        """Number of terms to use (by default) in modelling the S11.

        Raises
        ------
        ValueError :
            If n_terms is even.
        """
        res = self._nterms or self.default_nterms.get(self.load_name, None)
        if not (isinstance(res, int) and res % 2):
            raise ValueError(
                f"n_terms must be odd for S11 models. For {self.load_name} got n_terms={res}."
            )
        return res

I get the error about raising ValueError, even though it's in the docstring. Any help appreciated!

terrencepreilly commented 4 years ago

It's not expecting the colon after ValueError. It should raise a style error so it's more obvious. Let's add this to Issue #69 for tracking, and I'm mark it as an enhancement.

steven-murray commented 4 years ago

Ah, thanks. I'll fix that up. A better error would definitely make it easier to diagnose!

terrencepreilly commented 4 years ago

An error message will be present in v1.5.2. To handle it, I've allowed specifying types on errors. Just a colon will display an empty type error. (See b73bae737d214652a0862d26e1b3753905e66739.)

steven-murray commented 4 years ago

Great, that sounds like a good solution! Thanks!