I want to force a child class to implement or override all of the inherited methods from a parent class, but I want to allow the parent class to be instantiated. Therefore, I need the parent class to have a proper implementation rather than simply raising NotImplementedError exceptions.
If a child class does not override all of its parent's methods, I want the Python interpreter to scream at me.
For example:
class Parent:
# This __init__() doesn't matter, I can change it to whatever
def __init__(self):
pass
def foo(self):
print("Parent::foo()")
def bar(self):
print("Parent::bar()")
class Child(Parent):
# This __init__() doesn't matter, I can change it to whatever
def __init__(self):
pass
# The interpreter should complain about a missing override for foo()
def bar(self):
print("Child::bar()")
# Parent cannot be abstract because I want to instantiate
parent = Parent()
# As soon as I create the Child object, or even before, I want the
# interpreter to stop me due to the missing override for Parent::foo()
child = Child()
I would prefer an approach geared towards Python 2 since that's what I use at work, but I would be glad and happy to read any approach for Python 3 because that's what I use at home.