(
    filepath: types.PathLike,
    *,
    mode: str = "rt",
    encoding: Optional[str] = None,
    errors: Optional[str] = None,
    newline: Optional[str] = None,
    compression: Literal["infer", "bz2", "gzip", "xz", "zip"] = "infer",
    make_dirs: bool = False,
)
return f
Open file ``filepath``. Automatically handle file compression, relative
    paths and symlinks, and missing intermediate directory creation, as needed.

    ``open_sesame`` may be used as a drop-in replacement for :func:`io.open`.

    Args:
        filepath: Path on disk (absolute or relative) of the file to open.
        mode: The mode in which ``filepath`` is opened.
        encoding: Name of the encoding used to decode or encode ``filepath``.
            Only applicable in text mode.
        errors: String specifying how encoding/decoding errors are handled.
            Only applicable in text mode.
        newline: String specifying how universal newlines mode works.
            Only applicable in text mode.
        compression: Type of compression, if any, with which ``filepath``
            is read from or written to disk. If None, no compression is used;
            if 'infer', compression is inferred from the extension on ``filepath``.
        make_dirs: If True, automatically create (sub)directories
            if not already present in order to write ``filepath``.

    Returns:
        file object

    Raises:
        TypeError: if ``filepath`` is not a string
        ValueError: if ``encoding`` is specified but ``mode`` is binary
        OSError: if ``filepath`` doesn't exist but ``mode`` is read
Open file ``filepath``. Automatically handle file compression, relative
    paths and symlinks, and missing intermediate directory creation, as needed.
Open file filepath . Automatically handle file compression relative paths and symlinks and missing intermediate directory creation as needed .
def open_sesame(
    filepath: types.PathLike,
    *,
    mode: str = "rt",
    encoding: Optional[str] = None,
    errors: Optional[str] = None,
    newline: Optional[str] = None,
    compression: Literal["infer", "bz2", "gzip", "xz", "zip"] = "infer",
    make_dirs: bool = False,
) -> IO:
    """
    Open file ``filepath``. Automatically handle file compression, relative
    paths and symlinks, and missing intermediate directory creation, as needed.

    ``open_sesame`` may be used as a drop-in replacement for :func:`io.open`.

    Args:
        filepath: Path on disk (absolute or relative) of the file to open.
        mode: The mode in which ``filepath`` is opened.
        encoding: Name of the encoding used to decode or encode ``filepath``.
            Only applicable in text mode.
        errors: String specifying how encoding/decoding errors are handled.
            Only applicable in text mode.
        newline: String specifying how universal newlines mode works.
            Only applicable in text mode.
        compression: Type of compression, if any, with which ``filepath``
            is read from or written to disk. If None, no compression is used;
            if 'infer', compression is inferred from the extension on ``filepath``.
        make_dirs: If True, automatically create (sub)directories
            if not already present in order to write ``filepath``.

    Returns:
        file object

    Raises:
        TypeError: if ``filepath`` is not a string
        ValueError: if ``encoding`` is specified but ``mode`` is binary
        OSError: if ``filepath`` doesn't exist but ``mode`` is read
    """
    # check args
    if encoding and "t" not in mode:
        raise ValueError("encoding only applicable for text mode")

    # normalize filepath and make dirs, as needed
    filepath = utils.to_path(filepath).resolve()
    if make_dirs is True:
        _make_dirs(filepath, mode)
    elif mode.startswith("r") and not filepath.is_file():
        raise OSError(f"file '{filepath}' does not exist")

    compression = _get_compression(filepath, compression)
    f = _get_file_handle(
        filepath,
        mode,
        compression=compression,
        encoding=encoding,
        errors=errors,
        newline=newline,
    )
    return f
def open_sesame ( filepath : types . PathLike , * , mode : str = "rt" , encoding : Optional [ str ] = None , errors : Optional [ str ] = None , newline : Optional [ str ] = None , compression : Literal [ "infer" , "bz2" , "gzip" , "xz" , "zip" ] = "infer" , make_dirs : bool = False , ) -> IO : # check args if encoding and "t" not in mode : raise ValueError ( "encoding only applicable for text mode" ) # normalize filepath and make dirs, as needed filepath = utils . to_path ( filepath ) . resolve ( ) if make_dirs is True : _make_dirs ( filepath , mode ) elif mode . startswith ( "r" ) and not filepath . is_file ( ) : raise OSError ( f"file '{filepath}' does not exist" ) compression = _get_compression ( filepath , compression ) f = _get_file_handle ( filepath , mode , compression = compression , encoding = encoding , errors = errors , newline = newline , ) return f