Pylint W0223: Method ... is abstract in class ... but is not overridden

In order to shut up the wrong abstract-method warning you can implement abstract classes with abc.ABC superclass instead of using abc.ABCMeta metaclass.

For example, this code will raise the warning:

from abc import ABCMeta, abstractmethod


class Parent:
    __metaclass__ = ABCMeta

    @abstractmethod
    def do_something(self):
        pass


class Child(Parent):
    __metaclass__ = ABCMeta

but this will not:

from abc import ABC, abstractmethod


class Parent(ABC):

    @abstractmethod
    def do_something(self):
        pass


class Child(Parent, ABC):
    pass

Caution! With ABC superclass and multiple inheritance you have to watch out for potential Method Resolution Order (MRO) problems.


For some reason pylint think the class isn't abstract (currenly detection is done by checking for method which raise NotImplementedError). Adding a comment like #pylint: disable=W0223 at the top of the module (for disabling only in this module) or class (only in this class), should do the trick.

Tags:

Python

Pylint