You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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
The description of B024 in flake8-bugbear is:
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
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
"The text was updated successfully, but these errors were encountered: