code: def get_common_ancestor(paths: Iterable[Path]) -> Path:
      common_ancestor: Optional[Path] = None
      for path in paths:
          if not path.exists():
              continue
          if common_ancestor is None:
              common_ancestor = path
          else:
              if (
                  common_ancestor in path.parents
                  or path == common_ancestor
              ):
                  continue
              elif path in common_ancestor.parents:
                  common_ancestor = path
              else:
                  shared = commonpath(path, common_ancestor)
                  if shared is not None:
                      common_ancestor = shared
      if common_ancestor is None:
          common_ancestor = Path.cwd()
      elif common_ancestor.is_file():
          common_ancestor = common_ancestor.parent
      return common_ancestor
  
imports: import os
  import sys
  from pathlib import Path
  from typing import Dict
  from typing import Iterable
  from typing import List
  from typing import Optional
  from typing import Sequence
  from typing import Tuple
  from typing import TYPE_CHECKING
  from typing import Union
  import iniconfig
  from .exceptions import UsageError
  from _pytest.outcomes import fail
  from _pytest.pathlib import absolutepath
  from _pytest.pathlib import commonpath
  from _pytest.pathlib import safe_exists
label_desc: Use image node_id 4 for calling a global function with example usage: get_common_ancestor(paths) and returns: common_ancestor