def METHOD_NAME(basename:str, addition:str, swapsuffix:str = None) -> str:
    # Given a filename with an extension, extend the pre-extension part of the filename with the
    # desired addition, adding an underscore first if needed
    fn_base, fn_ext = os.path.splitext(basename)
    if not addition.startswith('_') and not basename.endswith('_'):
        addition = '_' + addition
    if swapsuffix is not None:
        if not swapsuffix.startswith('.'):
            swapsuffix = '.' + swapsuffix
        return fn_base + addition + swapsuffix
    else:
        return fn_base + addition + fn_ext