def __exit__(self, _type, _value, _tb): """ Restore the algo instance stored in __enter__. """ set_algo_instance(self.old_algo_instance)
def __enter__(self): """ Set the given algo instance, storing any previously-existing instance. """ self.old_algo_instance = get_algo_instance() set_algo_instance(self.algo_instance)