I have an abstract base class, Animal
:
class Animal(metaclass=abc.ABCMeta):
@abc.abstractmethod
def move(self):
raise NotImplementedError()
@abc.abstractmethod
def eat(self):
raise NotImplementedError()
Now I have another abc that only implements one of these methods:
class Bird(Animal):
def move(self):
print("fly")
An another class that implements the missing method:
class Eagle(Bird):
def eat(self):
print("eagle eats")
But PyCharm is complaining about Bird
that it "must implement all abstract methods", when I intentionally want it to stay abstract still.
Am I missing something, or is this a bug? If it's just a bug, can I ignore the warning somehow (similar to #noqa
)?
Just mark Bird
as abstract too:
from abc import ABC
class Bird(Animal, ABC):
def move(self):
print("fly")
After thinking about it a little, actually, I think that for this purpose it would make more sense to specify metaclass=ABCMeta
, as you did originally, since conceptually we do not want to modify the inheritance hierarchy of Bird
, but rather mark it as also an abstract class (for PyCharm's benefit), and perhaps that is a cleaner way of doing so.
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