Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC202 false positive with abstract methods #12685

Closed
mhooreman opened this issue Aug 5, 2024 · 2 comments · Fixed by #12771
Closed

DOC202 false positive with abstract methods #12685

mhooreman opened this issue Aug 5, 2024 · 2 comments · Fixed by #12771
Assignees
Labels
docstring Related to docstring linting or formatting rule Implementing or modifying a lint rule

Comments

@mhooreman
Copy link

mhooreman commented Aug 5, 2024

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
@charliermarsh
Copy link
Member

Do you still see this in the latest release? We ignore stub functions already, so the example above doesn't raise a violation: https://play.ruff.rs/c6b7a90d-26a2-4a50-9b0a-8d5b0259a85f

@edgarrmondragon
Copy link
Contributor

Do you still see this in the latest release? We ignore stub functions already, so the example above doesn't raise a violation: https://play.ruff.rs/c6b7a90d-26a2-4a50-9b0a-8d5b0259a85f

0.5.7 did seem to fix it for me :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docstring Related to docstring linting or formatting rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants