Consider the following sample snippet
import abc
class BASE(metaclass=abc.ABCMeta):
def __init__(self, name):
assert name is not None, "Name must be provided."
self.num = 3
@abc.abstractmethod
def compute(self):
pass
class CHILD(BASE):
def __init__(name):
'''
'''
def compute(self):
return self.num + 34
On execution it gives the following sensible error :
AttributeError: 'CHILD' object has no attribute 'num'
In the present situation BASE is not being initialized because if we add a print function to it as below, it does not print absolutely anything.
class BASE(metaclass=abc.ABCMeta):
def __init__(self, name):
print(name)
assert name is not None, "Name must be provided."
self.num = 3
Can we do anything in this class design to make sure that an implementor subclassing from BASE
must explicitly call the initializer of the BASE
?