def make_persistent_attribute(name, default=None):
    backend_attr = '__%s' % hex(random.getrandbits(128))
    def _getter(self):
        if not hasattr(self, backend_attr):
            setattr(self, name, default)
        return getattr(self, backend_attr)
    def _setter(self, value):
        if hasattr(self, backend_attr) and value == getattr(self, backend_attr):
            return
        self._changed = True
        if self.mutable:
            setting = self._pending_updates.setdefault('$set', {})
            setting[name] = value
        else:
            self._pending_updates[name] = value
        setattr(self, backend_attr, value)
    return property(_getter, _setter)
dataset/ETHPy150Open ebroder/anygit/anygit/backends/mongodb.py/make_persistent_attribute/original