Skip to content

abstract-base-class-without-abstract-method (B024)#

Derived from the flake8-bugbear linter.

What it does#

Checks for abstract classes without abstract methods.

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.

Example#

from abc import ABC


class Foo(ABC):
    def method(self):
        bar()

Use instead:

from abc import ABC, abstractmethod


class Foo(ABC):
    @abstractmethod
    def method(self):
        bar()

References#