def __enter__(self): if isinstance(self.orig, dict): self.getter, self.setter, self.deleter = dictget, dictset, dictdel else: self.getter, self.setter, self.deleter = getattr, setattr, delattr self.diff = change(self.orig, self.getter, self.setter, self.deleter, **self.attrs) return self
def alter(obj, **changes): """ Alternative API entry: a two step altering procedure. Same as `state`, but returns a function that will restore the changes at a later point. """ diff = change(obj, **changes) def restoration(): restore(obj, diff) return restoration
def alter(obj, **changes): """ Alternative API entry: a two step altering procedure. Same as `state`, but returns a function that will restore the changes at a later point. """ getter, setter, deleter = changers(obj) diff = change(obj, getter, setter, deleter, **changes) def restoration(): restore(obj, diff, getter, setter, deleter) return restoration
def __enter__(self): self.diff = change(self.orig, **self.attrs) return self
def __enter__(self): self.getter, self.setter, self.deleter = changers(self.orig) self.diff = change(self.orig, self.getter, self.setter, self.deleter, **self.attrs) return self