darglint icon indicating copy to clipboard operation
darglint copied to clipboard

DAR201 Request for Missing Return on abstractmethod

Open erikvanderwerf opened this issue 3 years ago • 1 comments

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.

erikvanderwerf avatar Nov 23 '21 18:11 erikvanderwerf

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.

joshua-cannon-techlabs avatar Nov 30 '21 18:11 joshua-cannon-techlabs