def METHOD_NAME(
    cls, url: URL, impersonate_user: bool, username: Optional[str]
) -> URL:
    """
    Return a modified URL with the username set.
    :param url: SQLAlchemy URL object
    :param impersonate_user: Flag indicating if impersonation is enabled
    :param username: Effective username
    """
    if impersonate_user and username is not None:
        if url.drivername == "drill+odbc":
            url = url.update_query_dict({"DelegationUID": username})
        elif url.drivername in ["drill+sadrill", "drill+jdbc"]:
            url = url.update_query_dict({"impersonation_target": username})
        else:
            raise SupersetDBAPIProgrammingError(
                f"impersonation is not supported for {url.drivername}"
            )
    return url