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

[docs] Description of B024&B027 is too assertive, as compared flake8-bugbear #11334

Closed
jakkdl opened this issue May 8, 2024 · 0 comments · Fixed by #11341
Closed

[docs] Description of B024&B027 is too assertive, as compared flake8-bugbear #11334

jakkdl opened this issue May 8, 2024 · 0 comments · Fixed by #11341
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@jakkdl
Copy link

jakkdl commented May 8, 2024

The description of B024 in flake8-bugbear is:

B024: Abstract base class has methods, but none of them are abstract. This is not necessarily an error, but you might have forgotten to add the @abstractmethod decorator, potentially in conjunction with @classmethod, @property and/or @staticmethod.

Which is explicitly saying "this is not necessarily an error" - there are plenty cases where you want a class to be abstract without it having abstract methods. Ruff's description is

Why is this bad?

Abstract base classes are used to define interfaces. If they have no abstract methods, they are not useful.

If the class is not meant to be used as an interface, it should not be an abstract base class. Remove the ABC base class from the class definition, or add an abstract method to the class.

Noticed in python-trio/trio#2997, where we have a base class that should never be instantiated directly (i.e. it's abstract) - but it has default (empty) implementations for all methods, and subclasses can choose which ones to override. There was also a ton of complaints on my initial implementation of B024 over false positives - we've narrowed the check since then (I hope yours also is) to silence most of those, but it's very far from an iron-clad rule.

B027 has a similar problem https://docs.astral.sh/ruff/rules/empty-method-without-abstract-decorator/ vs "consider adding @abstractmethod"

@jakkdl jakkdl changed the title [docs] Description of B024 is too assertive, as compared flake8-bugbear [docs] Description of B024&B027 is too assertive, as compared flake8-bugbear May 8, 2024
@AlexWaygood AlexWaygood added the documentation Improvements or additions to documentation label May 8, 2024
@charliermarsh charliermarsh self-assigned this May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants