If you want to make absolutely sure that the subclasses are Aoverride SIZE, you can use the metaclass for A, which will throw an error if the subclass does not override it (note that this Ais a new-style class):
class ClassWithSize(type):
def __init__(cls, name, bases, attrs):
if 'SIZE' not in attrs:
raise NotImplementedError('The "%s" class does not implement a "SIZE" attribute' % name)
super(ClassWithSize, cls).__init__(name, bases, attrs)
class A(object):
__metaclass__ = ClassWithSize
SIZE = 5
def getsize(self):
return self.SIZE
class B(A):
SIZE = 6
class C(A):
pass
, , C.