jdkandersson / flake8-docstrings-complete

Apache License 2.0
12 stars 2 forks source link

Error DCO031 in abstract methods #24

Open ni-co-la opened 10 months ago

ni-co-la commented 10 months ago

If I have the following code:

from abc import ABCMeta, abstractmethod
from typing import override

def main() -> None:
    """Main."""
    print('main')

    foo = FooImpl()
    print(foo.get_name())

class FooInterface(metaclass=ABCMeta):
    """Interface Foo."""

    @abstractmethod
    def get_name(self) -> str:
        """Return name.

        Returns:
            str: Name
        """

class FooImpl(FooInterface):
    """Foo."""

    @override
    def get_name(self) -> str:
        """Return name.

        Returns:
            str: Name
        """
        return 'Foo'

if __name__ == '__main__':
    main()

It fails (DCO031) because there is a return documented in the abstract method get_name() in class FooInterface, but there is no return implemented. The documented return value is necessary, as it fully describes the abstract method and how it can be used. Every class implementing the interface, shall know what the expected return value needs to be.