Repository: astral-sh/uv
File: crates/uv/src/commands/auth/helper.rs (Rust)

Code before:
        }
        Ok(Self { headers })
    }

    type Error = anyhow::Error;
}

async fn credentials_for_url(
    url: &DisplaySafeUrl,
    preview: Preview,
    network_settings: &NetworkSettings,
) -> Result<Option<Credentials>> {
    let pyx_store = PyxTokenStore::from_settings()?;

    // Use only the username from the URL, if present - discarding the password
    let url_credentials = Credentials::from_url(url);
    let url_username = url_credentials.as_ref().and_then(|c| c.username());
    let username = url_username.map(ToString::to_string);

    if pyx_store.is_known_domain(url) {
        if username.is_some() {
            bail!(
                "Cannot specify a username for URLs under {}",
                url.host()
                    .map(|host| host.to_string())
                    .unwrap_or("this host".to_owned())
            );
        }
        let client = BaseClientBuilder::new(
            network_settings.connectivity,
            network_settings.native_tls,
            network_settings.allow_insecure_host.clone(),
            preview,
            network_settings.timeout,
            network_settings.retries,
        )
        .auth_integration(uv_client::AuthIntegration::NoAuthMiddleware)
        .build();
        let maybe_token = pyx_store
            .access_token(client.for_host(pyx_store.api()).raw_client(), 0)
            .await
            .context("Authentication failure")?;
        let token = maybe_token.ok_or_else(|| anyhow::anyhow!("No access token found"))?;
        return Ok(Some(Credentials::bearer(token.into_bytes())));
    }
    let backend = AuthBackend::from_settings(preview)?;
    let credentials = match &backend {
        AuthBackend::System(provider) => provider.fetch(url, username.as_deref()).await,
        AuthBackend::TextStore(store, _lock) => {
            store.get_credentials(url, username.as_deref()).cloned()
        }

Review comment (suggestion):
```suggestion
                    .unwrap_or(url.to_string())
```

Code after:
    type Error = anyhow::Error;
}

async fn credentials_for_url(
    url: &DisplaySafeUrl,
    preview: Preview,
    network_settings: &NetworkSettings,
) -> Result<Option<Credentials>> {
    let pyx_store = PyxTokenStore::from_settings()?;

    // Use only the username from the URL, if present - discarding the password
    let url_credentials = Credentials::from_url(url);
    let username = url_credentials.as_ref().and_then(|c| c.username());
    if url_credentials
        .as_ref()
        .map(|c| c.password().is_some())
        .unwrap_or(false)
    {
        debug!("URL '{url}' contain a password; ignoring");
    }

    if pyx_store.is_known_domain(url) {
        if username.is_some() {
            bail!(
                "Cannot specify a username for URLs under {}",
                url.host()
                    .map(|host| host.to_string())
                    .unwrap_or(url.to_string())
            );
        }
        let client = BaseClientBuilder::new(
            network_settings.connectivity,
            network_settings.native_tls,
            network_settings.allow_insecure_host.clone(),
            preview,
            network_settings.timeout,
            network_settings.retries,
        )
        .auth_integration(uv_client::AuthIntegration::NoAuthMiddleware)
        .build();
        let token = pyx_store
            .access_token(client.for_host(pyx_store.api()).raw_client(), 0)
            .await
            .context("Authentication failure")?
            .context("No access token found")?;
        return Ok(Some(Credentials::bearer(token.into_bytes())));
    }
    let backend = AuthBackend::from_settings(preview).await?;
    let credentials = match &backend {
        AuthBackend::System(provider) => provider.fetch(url, username).await,
        AuthBackend::TextStore(store, _lock) => store.get_credentials(url, username).cloned(),