code: def setenv_optional(key: str, val: Optional[str]) -> Iterator:
      old = os.environ.get(key)
      if val is None:
          os.environ.pop(key, None)
      else:
          os.environ[key] = val
      try:
          yield
      finally:
          if old is None:
              os.environ.pop(key, None)
          else:
              os.environ[key] = old
  
imports: import contextlib
  import os
  from typing import Any, Iterator, List, Optional, cast
  import responses
  from responses import registries
  import determined
  from determined.common.api import authentication
label_desc: Use image node_id 1 for calling a global function with example usage: setenv_optional(key, val) without return types