def METHOD_NAME(filename: Union[str, bytes]) -> str:
    ''' Tidies a filename
    Keeps the filename extension (e.g. .csv).
    Strips off any path on the front.
    Returns a Unicode string.
    '''
    if not isinstance(filename, str):
        filename = decode_path(filename)
    # Ignore path
    filename = os.path.split(filename)[1]
    # Clean up
    filename = filename.lower().strip()
    filename = substitute_ascii_equivalents(filename)
    filename = re.sub(u'[^a-zA-Z0-9_. -]', '', filename).replace(u' ', u'-')
    filename = re.sub(u'-+', u'-', filename)
    # Enforce length constraints
    name, ext = os.path.splitext(filename)
    ext = ext[:MAX_FILENAME_EXTENSION_LENGTH]
    ext_len = len(ext)
    name = _munge_to_length(name, max(1, MIN_FILENAME_TOTAL_LENGTH - ext_len),
                            MAX_FILENAME_TOTAL_LENGTH - ext_len)
    filename = name + ext
    return filename