code: def delattr_ctx(
      instance: object, *attrs: str, enforce_hasattr: bool = False
  ) -> Generator[None, None, None]:
      r"""Contextmanager for temporarily deleting attributes."""
      try:
          cache = {}
          for key in attrs:
              if hasattr(instance, key):
                  cache[key] = getattr(instance, key)
                  delattr(instance, key)
              elif enforce_hasattr:
                  raise ValueError(
                      f"Attribute {key} missing from {type(instance)} instance."
                  )
          yield
      finally:
          for key, cached_val in cache.items():
              setattr(instance, key, cached_val)
  
file_path: botorch/botorch/utils/context_managers.py
imports: from __future__ import annotations
  from contextlib import contextmanager
  from typing import Any, Callable, Dict, Generator, Iterable, NamedTuple, Optional, Union
  from torch import device, dtype, Tensor
  from torch.nn import Module
label_desc: Use image node_id 1 for calling a global function with example usage: delattr_ctx(instance) without return types