メタクラスを使用できます:
class AutoExtendingFoo(type):
def __new__(cls, name, bases, attrs):
foo = []
for base in bases:
try:
foo.extend(getattr(base, 'foo'))
except AttributeError:
pass
try:
foo.extend(attrs.pop('foo_additions'))
except KeyError:
pass
attrs['foo'] = foo
return type.__new__(cls, name, bases, attrs)
class A(object):
__metaclass__ = AutoExtendingFoo
foo_additions = ['thing1', 'thing2']
# will have A.foo = ['thing1', 'thing2']
class B(A):
foo_additions = ['thing3', 'thing4']
# will have B.foo = ['thing1', 'thing2', 'thing3', 'thing4']
class C(A):
pass
# will have C.foo = ['thing1', 'thing2']
class D(B):
pass
# will have D.foo = ['thing1', 'thing2', 'thing3', 'thing4']