Back to Intellij Community

PyAbstractClassInspection

python/python-psi-impl/resources/inspectionDescriptions/PyAbstractClassInspection.html

2025.3-rc-2948 B
Original Source

Reports invalid definition and usages of abstract classes.

Example:

from abc import abstractmethod, ABC

class Figure(ABC):

    @abstractmethod
    def do_figure(self):
        pass

class Triangle(Figure): # Not all abstract methods are defined in 'Triangle' class
    def do_triangle(self):
        pass

Triangle() # Cannot instantiate abstract class 'Triangle'

When the quick-fix is applied, the IDE implements an abstract method for the Triangle class:

from abc import abstractmethod, ABC

class Figure(ABC):

    @abstractmethod
    def do_figure(self):
        pass

class Triangle(Figure):
    def do_figure(self):
        pass

    def do_triangle(self):
        pass

Triangle()

It also warns you if abc.abstractmethod is used in a class whose metaclass is not abc.ABCMeta:

from abc import abstractmethod

class MyClass:
    @abstractmethod # 'MyClass' is not abstract
    def foo(self):
        ...