code: def _open_config_file(config_file: str | IO | None) -> Iterator[IO]:
      """
      A context manager which yields an open file descriptor ready to be read.
  
      Accepts a filename as a string, an open or closed file descriptor, or None.
      When None, it defaults to `mkdocs.yml` in the CWD. If a closed file descriptor
      is received, a new file descriptor is opened for the same file.
  
      The file descriptor is automatically closed when the context manager block is existed.
      """
      # Default to the standard config filename.
      if config_file is None:
          paths_to_try = ["mkdocs.yml", "mkdocs.yaml"]
      # If it is a string, we can assume it is a path and attempt to open it.
      elif isinstance(config_file, str):
          paths_to_try = [config_file]
      # If closed file descriptor, get file path to reopen later.
      elif getattr(config_file, "closed", False):
          paths_to_try = [config_file.name]
      else:
          result_config_file = config_file
          paths_to_try = None
  
      if paths_to_try:
          # config_file is not a file descriptor, so open it as a path.
          for path in paths_to_try:
              path = os.path.abspath(path)
              log.debug(f"Loading configuration file: {path}")
              try:
                  result_config_file = open(path, "rb")
                  break
              except FileNotFoundError:
                  continue
          else:
              raise exceptions.ConfigurationError(
                  f"Config file '{paths_to_try[0]}' does not exist."
              )
      else:
          log.debug(f"Loading configuration file: {result_config_file}")
          # Ensure file descriptor is at beginning
          try:
              result_config_file.seek(0)
          except OSError:
              pass
  
      try:
          yield result_config_file
      finally:
          if hasattr(result_config_file, "close"):
              result_config_file.close()
  
imports: from __future__ import annotations
  import functools
  import logging
  import os
  import sys
  import warnings
  from collections import UserDict
  from contextlib import contextmanager
  from typing import IO, TYPE_CHECKING, Any, Generic, Iterator, List, Mapping, Sequence, Tuple, TypeVar, overload
  from mkdocs import exceptions, utils
  from mkdocs.utils import weak_property
label_desc: Use image node_id 2 for calling a global function with example usage: _open_config_file(config_file) without return types