Pylint generates this error for subclasses of an abstract class, even when those subclasses are not themselves instantiated and the methods are overridden in the concrete subclasses. Why does Pylint think my abstract subclasses are intended to be concrete? How can I shut up this warning without getting out the hammer and disabling it altogether in the rc file?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With