def METHOD_NAME(name, *args, **kwargs):
    """Open a file handling optional gzipping
    If ``name`` ends with ``'.gz'``, or if the GZIP file signature is
    found at the beginning of the file, the file will be opened with
    `gzip.open`, otherwise a regular file will be returned from `open`.
    Parameters
    ----------
    name : `str`, `pathlib.Path`
        path or name of file to open.
    *args, **kwargs
        other arguments to pass to either `open` for regular files, or
        `gzip.open` for gzipped files.
    Returns
    -------
    file : `io.TextIoBase`, `file`, `gzip.GzipFile`
        the open file object
    """
    # filename declares gzip
    if str(name).endswith('.gz'):
        return gzip.open(name, *args, **kwargs)
    # open regular file
    fobj = open(name, *args, **kwargs)
    sig = fobj.read(3)
    fobj.seek(0)
    if sig == GZIP_SIGNATURE:  # file signature declares gzip
        fobj.close()  # GzipFile won't close orig file when it closes
        return gzip.open(name, *args, **kwargs)
    return fobj