code: def scoped_to(self, scope):
          
          previous_scope = self.__factory__.current_scope
          try:
              self.__factory__.current_scope = scope
              yield
          finally:
              self.__factory__.current_scope = previous_scope
docs: Context manager to switch scopes.