code: def _apply(
      repo: "Repo",
      rev: str,
      name: Optional[str] = None,
      is_stash: bool = False,
  ):
      exps: "Experiments" = repo.experiments
  
      with exps.apply_stash.preserve_workspace(rev, name=name):
          with repo.scm.detach_head(rev, force=True):
              if is_stash:
                  assert repo.tmp_dir is not None
                  args_path = os.path.join(
                      repo.tmp_dir, BaseExecutor.PACKED_ARGS_FILE
                  )
                  if os.path.exists(args_path):
                      remove(args_path)
  
file_path: dvc/dvc/repo/experiments/apply.py
imports: import os
  from typing import TYPE_CHECKING, Optional
  from dvc.log import logger
  from dvc.repo import locked
  from dvc.repo.scm_context import scm_context
  from dvc.scm import Git
  from dvc.ui import ui
  from dvc.utils.fs import remove
  from .exceptions import BaselineMismatchError, InvalidExpRevError
  from .executor.base import BaseExecutor
  from .refs import EXEC_APPLY
label_desc: Use image node_id 2 for calling a global function with example usage: _apply(repo, rev, name, is_stash) without return types