def clip_suffix(string: str, suffix: str, req=True) ->str:
    """Remove `suffix`if it is present, or raise ValueError, unless `req` is False."""
    if len(suffix) == 0:
        return string
    if string.endswith(suffix):
        return string[:-len(suffix)]
    elif req:
        raise ValueError(string)
    return string
