code: def _find_editor(environ: Mapping[str, str]) -> str:
      candidates = _default_editors()
      for i, var in enumerate(("EDITOR", "VISUAL")):
          if var in environ:
              user_choice = environ[var]
              if exists(user_choice):
                  return user_choice
              if os.sep not in user_choice:
                  candidates.insert(i, user_choice)
  
      for candidate in candidates:
          path = _find_executable(candidate, environ)
          if path is not None:
              return path
      raise OSError(
          "No suitable editor found. Please set the "
          '"EDITOR" or "VISUAL" environment variables'
      )
  
file_path: alembic/alembic/util/editor.py
imports: from __future__ import annotations
  import os
  from os.path import exists
  from os.path import join
  from os.path import splitext
  from subprocess import check_call
  from typing import Dict
  from typing import List
  from typing import Mapping
  from typing import Optional
  from .compat import is_posix
  from .exc import CommandError
label_desc: Use image node_id 2 for calling a global function with example usage: _find_editor(environ) and returns: path, user_choice