What is the pythonic way to have an intermediate class that overwrites some of the method’s from an Abstract parent, but not all. Must it also overwrite methods it does not wish to change?
class Animal(six.with_metaclass(ABCMeta, object)):):
@abstractmethod
def move(self):
raise NotImplementedError()
@abstractmethod
def give_birth(self):
raise NotImplementedError()
class Mammal(Animal):
def move(self): # I want to inherit this method from Animal
raise NotImplementedError()
def give_birth(self): # want to overwrite
# not with eggs!
class Dog(Mammal):
def move(self):
return 'MOVED like a dog'
This code doesn’t actually break, but my IDE (pycharm) highlights “class Mammal” and says “must implement all abstract methods". Maybe Animal.move shouldn't be abstract?
movefromAnimalbut it's an abstract method so it doesn't have an implementation inAnimal. You'll have to make a concrete implementation ofAnimal.move(i.e. not anabstractmethod) if you want to inherit it as you say. What exactly is confusing you?Animal.get_move? What identical code, I don't see any code repitition? Why is this solution not satisfactory? Can you be a bit more clear?