class Expression(object): .... + def __setattr__(self, name, value): + """ + Protect expression objects from being modified, so they can be safely shared, in particular in L{Expression.reduce}. + """ + raise AttributeError("Not allowed to set \"{}\"".format(name)) + + def set_value(self, name, value): + """ + Set a variable to a value. Should only be used in constructors to preserve sharable property of the objects. + + @param name: Name of the attribute to set. + @type name: C{str} + + @param value: New value of the attribute. + @type value: anything + """ + object.__setattr__(self, name, value)