terrencepreilly / darglint

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

DAR201 Request for Missing Return on abstractmethod #185

Open erikvanderwerf opened 3 years ago

erikvanderwerf commented 3 years ago
from abc import ABC, abstractmethod

class MySpam(ABC):
    """Docstring."""

    @abstractmethod
    def spam(self) -> str:
        """Spam."""                        <-- Missing
        raise NotImplementedError()

    def sausage(self) -> float:
        """Sausage."""                     <-- 13
        return 0.4

def eggs() -> int:
    """Eggs."""                            <-- 18
    return 3
$ flake8 --select DAR main.py 
main.py:13:1: DAR201 Missing "Returns" in Docstring: - return
main.py:18:1: DAR201 Missing "Returns" in Docstring: - return

$ flake8 --select DAR --strictness full main.py 
main.py:13:1: DAR201 Missing "Returns" in Docstring: - return
main.py:18:1: DAR201 Missing "Returns" in Docstring: - return

I would like to see a DAR201 (or new error) for a missing Returns docstring section on methods decorated as @abstractmethod. This is different than #54, as that issue related to not requiring an actual return statement in code, whereas this is strictly about the docstring. I have also checked that missing parameters are reported, as expected (not shown above).

This helps because it will require superclass interfaces to declare what their implementors should return.

joshua-cannon-techlabs commented 2 years ago

I agree with this. But to add on I think it can only be reported if there's a return type annotation, as not all methods return.