-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
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
@abstractmethoddecorator, potentially in conjunction with@classmethod,@propertyand/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"