Skip to content

DOC202 false positive with abstract methods #12685

@mhooreman

Description

@mhooreman

Hello,

Context:

  • An abstract method is defined
  • The docstring of this abstract method has a return statement
  • There is (obviously) no implementation in the abstract method ... and so no return statement

Actual result:

DOC202 Docstring should not have a returns section because the function doesn't return anything

Expected result:

No error

Keywords searched in issues list before creating this issue

  • DOC202

Code snippet:

import abc

class A(metaclass=abc.abcmeta):
    @abc.abstractmethod
    def f(self):
        """Lorem ipsum

        Returns
        -------
        dict:
            The values
        """

class C(A):
    def f(self):  # noqa: PLR6301 - this is for demo purpose
        return {}

Remarks:

  • Same result with type annotation given in the abstract method definition (e.g. def f(self) -> dict:)
  • In terms of implementation, a possibility could be to check if the method is decorated as abstract before doing this test

Metadata

Metadata

Assignees

Labels

docstringRelated to docstring linting or formattingruleImplementing or modifying a lint rule

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions