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

D102 not silent for overrides.overrides or overrides.override #12942

Closed
lengau opened this issue Aug 16, 2024 · 3 comments · Fixed by #12996
Closed

D102 not silent for overrides.overrides or overrides.override #12942

lengau opened this issue Aug 16, 2024 · 3 comments · Fixed by #12996
Labels
docstring Related to docstring linting or formatting

Comments

@lengau
Copy link
Contributor

lengau commented Aug 16, 2024

On ruff version 0.6.1, this file:

import typing
import overrides

class Base:
    "Sample class"

    def do_thing(self) -> None:
        "Do a thing."
        pass


class First(Base):
    "Success with typing.override"

    @typing.override
    def do_thing(self) -> None:
        pass


class FailueA(Base):
    "Failure with overrides.override"

    @overrides.override
    def do_thing(self) -> None:
        pass


class FailureB(Base):
    "Success with overrides.overrides"

    @overrides.overrides
    def do_thing(self) -> None:
        pass

gets flagged twice with D102:

$ ruff check sample.py --extend-select D102
sample.py:24:9: D102 Missing docstring in public method
   |
23 |     @overrides.override
24 |     def do_thing(self) -> None:
   |         ^^^^^^^^ D102
25 |         pass
   |

sample.py:32:9: D102 Missing docstring in public method
   |
31 |     @overrides.overrides
32 |     def do_thing(self) -> None:
   |         ^^^^^^^^ D102
33 |         pass
   |

Found 2 errors.

and I don't see a way in the docs to extend D102 to treat these decorators from overrides like typing.override

@charliermarsh charliermarsh added the docstring Related to docstring linting or formatting label Aug 18, 2024
@charliermarsh
Copy link
Member

Is that library still relevant with the advent of typing.override? (I'm not familiar with it, just confirming before we do anything about it.)

@lengau
Copy link
Contributor Author

lengau commented Aug 19, 2024

Valid question! The overrides library offers certain runtime capabilities that can't be done with static typing. For example, it has a metaclass that enforces the use of override decorators on child classes, even from other packages. The two use cases:

  1. If you use a library that uses the enforcement metaclass, you'd have to do a double decorator (typing.override and overrides.override) in order to please both ruff and overrides
  2. If you're providing a library that provides base classes, you may want to use this to ensure that people aren't accidentally overriding your methods on new versions, even if they don't use linters like ruff.

@lengau
Copy link
Contributor Author

lengau commented Aug 19, 2024

Actually, this works:

[tool.ruff.lint.pydocstyle]
ignore-decorators = [  # Functions with these decorators don't have to have docstrings.
    "typing.overload",  # Default configuration
    # The next four are all variations on override, so child classes don't have to repeat parent classes' docstrings.
    "overrides.override",
    "overrides.overrides",
    "typing.override",
    "typing_extensions.override",
]

so the issue is probably then just that the docs should mention that configuration option :-)

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants