def inherit_attribute(name, f):

    def decorator(cls):
        old_value = getattr(cls, name)
new_value = f([getattr(base, name) for base in cls.__bases__], old_value)
setattr(cls, name, new_value)
return cls
return decorator

def update_x(base_values, my_value):
    return sum(base_values + [my_value], tuple())


class Foo:
    x = 1,


@inherit_attribute('x', update_x)
class Bar(Foo):
    x = 2,
Bar.x
Accessing parent class attribute from sub-class body