code: def open_file(
      filename: str,
      mode: str = "r",
      encoding: t.Optional[str] = None,
      errors: t.Optional[str] = "strict",
      lazy: bool = False,
      atomic: bool = False,
  ) -> t.IO[t.Any]:
      """Open a file, with extra behavior to handle ``'-'`` to indicate
      a standard stream, lazy open on write, and atomic write. Similar to
      the behavior of the :class:`~click.File` param type.
  
      If ``'-'`` is given to open ``stdout`` or ``stdin``, the stream is
      wrapped so that using it in a context manager will not close it.
      This makes it possible to use the function without accidentally
      closing a standard stream:
  
      .. code-block:: python
  
          with open_file(filename) as f:
              ...
  
      :param filename: The name of the file to open, or ``'-'`` for
          ``stdin``/``stdout``.
      :param mode: The mode in which to open the file.
      :param encoding: The encoding to decode or encode a file opened in
          text mode.
      :param errors: The error handling mode.
      :param lazy: Wait to open the file until it is accessed. For read
          mode, the file is temporarily opened to raise access errors
          early, then closed until it is read again.
      :param atomic: Write to a temporary file and replace the given file
          on close.
  
      .. versionadded:: 3.0
      """
      if lazy:
          return t.cast(
              t.IO[t.Any],
              LazyFile(filename, mode, encoding, errors, atomic=atomic),
          )
  
      f, should_close = open_stream(
          filename, mode, encoding, errors, atomic=atomic
      )
  
      if not should_close:
          f = t.cast(t.IO[t.Any], KeepOpenFile(f))
  
      return f
  
imports: import os
  import re
  import sys
  import typing
  from functools import update_wrapper
  from types import ModuleType
  from types import TracebackType
  from ._compat import _default_text_stderr
  from ._compat import _default_text_stdout
  from ._compat import _find_binary_writer
  from ._compat import auto_wrap_for_ansi
  from ._compat import binary_streams
  from ._compat import open_stream
  from ._compat import should_strip_ansi
  from ._compat import strip_ansi
  from ._compat import text_streams
  from ._compat import WIN
  from .globals import resolve_color_default
label_desc: Use image node_id 8 for calling a global function with example usage: open_file(filename, mode, encoding, errors, lazy, atomic) and returns: f, t