ronantakizawa/codereview-bench huggingface dataset:
Repository: astral-sh/uv
File: crates/uv-platform-tags/src/platform.rs (Rust)

Code before:
            Self::Aarch64 => "aarch64",
            Self::Armv5TEL => "armv5tel",
            Self::Armv6L => "armv6l",
            Self::Armv7L => "armv7l",
            Self::Powerpc64Le => "ppc64le",
            Self::Powerpc64 => "ppc64",
            Self::Powerpc => "ppc",
            Self::X86 => "i686",
            Self::X86_64 => "x86_64",
            Self::S390X => "s390x",
            Self::LoongArch64 => "loongarch64",
            Self::Riscv64 => "riscv64",
            Self::Wasm32 => "wasm32",
        }
    }

    /// Represents the hardware platform.
    ///
    /// This is the same as the native platform's `uname -m` output.
    ///
    /// Based on: <https://github.com/PyO3/maturin/blob/8ab42219247277fee513eac753a3e90e76cd46b9/src/target/mod.rs#L131>
    pub fn machine(&self) -> &'static str {
        match self {
            Arch::Aarch64 => "arm64",
            Arch::Armv5TEL | Arch::Armv6L | Arch::Armv7L => "arm",
            Arch::Powerpc | Arch::Powerpc64Le | Arch::Powerpc64 => "powerpc",
            Arch::X86 => "i386",
            Arch::X86_64 => "amd64",
            Arch::Riscv64 => "riscv",
            Arch::Wasm32 => "wasm32",
            Arch::S390X => "s390x",
            Arch::LoongArch64 => "loongarch64",
        }
    }
}


Review comment (suggestion):
@konstin -- We can just wait until we get user feedback on it, but I'm surprised by this, I would've expected `powerpc64`.

Code after:
            Self::Aarch64 => "aarch64",
            Self::Armv5TEL => "armv5tel",
            Self::Armv6L => "armv6l",
            Self::Armv7L => "armv7l",
            Self::Powerpc64Le => "ppc64le",
            Self::Powerpc64 => "ppc64",
            Self::Powerpc => "ppc",
            Self::X86 => "i686",
            Self::X86_64 => "x86_64",
            Self::S390X => "s390x",
            Self::LoongArch64 => "loongarch64",
            Self::Riscv64 => "riscv64",
            Self::Wasm32 => "wasm32",
        }
    }

    /// Represents the hardware platform.
    ///
    /// This is the same as the native platform's `uname -m` output.
    ///
    /// Based on: <https://github.com/PyO3/maturin/blob/8ab42219247277fee513eac753a3e90e76cd46b9/src/target/mod.rs#L131>
    pub fn machine(&self) -> &'static str {
        match self {
            Self::Aarch64 => "arm64",
            Self::Armv5TEL | Self::Armv6L | Self::Armv7L => "arm",
            Self::Powerpc | Self::Powerpc64Le | Self::Powerpc64 => "powerpc",
            Self::X86 => "i386",
            Self::X86_64 => "amd64",
            Self::Riscv64 => "riscv",
            Self::Wasm32 => "wasm32",
            Self::S390X => "s390x",
            Self::LoongArch64 => "loongarch64",
        }
    }
}
Repository: astral-sh/uv
File: crates/uv/src/commands/publish.rs (Rust)

Code before:
        return None;
    }

    let upload = segments.next()?;
    if upload != "upload" {
        return None;
    }

    let workspace = segments.next()?;
    if workspace.is_empty() {
        return None;
    }

    let registry = segments.next()?;
    if registry.is_empty() {
        return None;
    }

    // Skip any empty segments (trailing slash handling)
    for remaining in segments {
        if !remaining.is_empty() {
            return None;
        }
    }

    // Reconstruct the URL with `/simple/{package}/`.
    let mut check_url = publish_url.clone();
    {
        let mut segments = check_url.path_segments_mut().ok()?;
        segments.clear();
        segments.push("simple").push(workspace).push(registry);
    }
    Some(IndexUrl::from(VerbatimUrl::from(check_url)))
}

#[cfg(test)]
mod tests {
    use super::*;

    use std::str::FromStr;

    use insta::assert_snapshot;

    use uv_redacted::DisplaySafeUrl;

    async fn get_credentials(
        url: DisplaySafeUrl,
        username: Option<String>,
        password: Option<String>,
    ) -> Result<(DisplaySafeUrl, Credentials)> {
        let client = BaseClientBuilder::default().build();

Review comment (suggestion):
```suggestion
    // Reconstruct the URL with `/simple/{workspace}/{registry}`.
```

Code after:
        return None;
    }

    let upload = segments.next()?;
    if upload != "upload" {
        return None;
    }

    let workspace = segments.next()?;
    if workspace.is_empty() {
        return None;
    }

    let registry = segments.next()?;
    if registry.is_empty() {
        return None;
    }

    // Skip any empty segments (trailing slash handling)
    for remaining in segments {
        if !remaining.is_empty() {
            return None;
        }
    }

    // Reconstruct the URL with `/simple/{workspace}/{registry}`.
    let mut check_url = publish_url.clone();
    {
        let mut segments = check_url.path_segments_mut().ok()?;
        segments.clear();
        segments.push("simple").push(workspace).push(registry);
    }
    Some(IndexUrl::from(VerbatimUrl::from(check_url)))
}

#[cfg(test)]
mod tests {
    use super::*;

    use std::str::FromStr;

    use insta::assert_snapshot;

    use uv_redacted::DisplaySafeUrl;

    async fn get_credentials(
        url: DisplaySafeUrl,
        username: Option<String>,
        password: Option<String>,
    ) -> Result<(DisplaySafeUrl, Credentials)> {
        let client = BaseClientBuilder::default().build();
Repository: astral-sh/uv
File: crates/uv/tests/it/pip_tree.rs (Rust)

Code before:
        context.pip_tree().arg("--outdated"), @r###"
    success: true
    exit_code: 0
    ----- stdout -----
    flask v2.0.0 (latest: v3.0.2)
    ├── click v8.1.7
    ├── itsdangerous v2.1.2
    ├── jinja2 v3.1.3
    │   └── markupsafe v2.1.5
    └── werkzeug v3.0.1
        └── markupsafe v2.1.5

    ----- stderr -----
    "###
    );
}

/// Test that dependencies with multiple marker-specific requirements
/// are only displayed once in the tree.
#[test]
#[cfg(feature = "pypi")]
fn no_duplicate_dependencies_with_markers() {
    let context = TestContext::new("3.12").with_exclude_newer("2026-01-01T00:00:00Z");

    let requirements_txt = context.temp_dir.child("requirements.txt");
    requirements_txt.write_str("pylint").unwrap();

    uv_snapshot!(context
        .pip_install()
        .arg("-r")
        .arg("requirements.txt")
        .arg("--strict"), @r###"
    success: true
    exit_code: 0
    ----- stdout -----

    ----- stderr -----
    Resolved 7 packages in [TIME]
    Prepared 7 packages in [TIME]
    Installed 7 packages in [TIME]
     + astroid==3.3.11
     + dill==0.4.0
     + isort==6.0.1
     + mccabe==0.7.0
     + platformdirs==4.4.0
     + pylint==3.3.8
     + tomlkit==0.13.3
    "###
    );

    // Ensure that dill is only listed once, even though pylint has multiple

Review comment (performance):
We might want to add a local package, e.g., to `scripts/packages` which has repeated `Requires-Dist` values. It's _okay_ to use pylint, but it'll make the test slower. We can track this in a separate issue if you prefer.

Code after:
    );

    uv_snapshot!(
        context.filters(),
        context.pip_tree().arg("--outdated"), @r###"
    success: true
    exit_code: 0
    ----- stdout -----
    flask v2.0.0 (latest: v3.0.2)
    ├── click v8.1.7
    ├── itsdangerous v2.1.2
    ├── jinja2 v3.1.3
    │   └── markupsafe v2.1.5
    └── werkzeug v3.0.1
        └── markupsafe v2.1.5

    ----- stderr -----
    "###
    );
}

/// Test that dependencies with multiple marker-specific requirements
/// are only displayed once in the tree.
#[test]
#[cfg(feature = "pypi")]
fn no_duplicate_dependencies_with_markers() {
    const PY_PROJECT: &str = indoc! {r#"
        [project]
        name = "debug"
        version = "0.1.0"
        requires-python = ">=3.12.0"
        dependencies = [
          "sniffio>=1.0.0; python_version >= '3.11'",
          "sniffio>=1.0.1; python_version >= '3.12'",
          "sniffio>=1.0.2; python_version >= '3.13'",
        ]

        [build-system]
        requires = ["uv_build>=0.8.22,<10000"]
        build-backend = "uv_build"
    "#};

    let context = TestContext::new_with_versions(&["3.12", "3.13"]).with_filtered_counts();

    let project = context.temp_dir.child("debug");

    project.create_dir_all().unwrap();

    project.child("src/debug").create_dir_all().unwrap();

    project.child("src/debug/__init__.py").touch().unwrap();
Repository: astral-sh/uv
File: crates/uv/tests/it/version.rs (Rust)

Code before:
    Ok(())
}

// Preserve comments immediately preceding the version when bumping
#[test]
fn version_bump_preserves_preceding_comments() -> Result<()> {
    let context = TestContext::new("3.12");

    let pyproject_toml = context.temp_dir.child("pyproject.toml");
    pyproject_toml.write_str(
        r#"
# hello
[project]
# hello
name = "hello-world"
# hello
version = "0.1.0"
# hello
description = "Add your description here"
# hello
readme = "README.md"
# hello
requires-python = ">=3.12"
# hello
dependencies = []
# hello
"#,
    )?;

    // Bump patch version
    context
        .version()
        .arg("--bump")
        .arg("patch")
        .assert()
        .success();

    // Ensure comments are preserved around the version entry
    let pyproject = fs_err::read_to_string(&pyproject_toml)?;
    assert_snapshot!(
        pyproject,
        @r#"
        # hello
        [project]
        # hello
        name = "hello-world"
        # hello
        version = "0.1.1"
        # hello
        description = "Add your description here"
        # hello

Review comment (suggestion):
This test case should use a more minimal `pyproject.toml`, and the comments should be different, so we see if e.g. the order changed.

Code after:
    Ok(())
}

/// Preserve comments immediately preceding the version when bumping
#[test]
fn version_bump_preserves_preceding_comments() -> Result<()> {
    let context: TestContext = TestContext::new("3.12");

    let pyproject_toml = context.temp_dir.child("pyproject.toml");
    pyproject_toml.write_str(
        r#"
        [project]
        name = "hello-world"
        # pre-1: stays above version
        # pre-2: stays below pre-1
        version = "0.1.0" # eol: stays on same line
        # after-version: remains after version
        description = "Add your description here"
        "#,
    )?;

    // Bump patch version
    context
        .version()
        .arg("--bump")
        .arg("patch")
        .assert()
        .success();

    // Ensure comments are preserved around the version entry
    let pyproject = fs_err::read_to_string(&pyproject_toml)?;
    assert_snapshot!(
        pyproject,
        @r#"
        [project]
        name = "hello-world"
        # pre-1: stays above version
        # pre-2: stays below pre-1
        version = "0.1.1" # eol: stays on same line
        # after-version: remains after version
        description = "Add your description here"
        "#
    );

    Ok(())
}

// Bump minor version
#[test]
fn version_bump_minor() -> Result<()> {
    let context = TestContext::new("3.12");
Repository: astral-sh/uv
File: crates/uv/tests/it/version.rs (Rust)

Code before:
        .arg("--bump").arg("patch")
        .arg("--short"), @r"
    success: true
    exit_code: 0
    ----- stdout -----
    1.10.32

    ----- stderr -----
    Resolved 1 package in [TIME]
    Audited in [TIME]
    ");

    let pyproject = fs_err::read_to_string(&pyproject_toml)?;
    assert_snapshot!(
        pyproject,
    @r#"
    [project]
    name = "myproject"
    version = "1.10.32"
    requires-python = ">=3.12"
    "#
    );
    Ok(())
}

// Preserve comments immediately preceding the version when bumping
#[test]
fn version_bump_preserves_preceding_comments() -> Result<()> {
    let context: TestContext = TestContext::new("3.12");

    let pyproject_toml = context.temp_dir.child("pyproject.toml");
    pyproject_toml.write_str(
        r#"
        [project]
        name = "hello-world"
        # pre-1: stays above version
        # pre-2: stays below pre-1
        version = "0.1.0" # eol: stays on same line
        # after-version: remains after version
        description = "Add your description here"
        "#,
    )?;

    // Bump patch version
    context
        .version()
        .arg("--bump")
        .arg("patch")
        .assert()
        .success();


Review comment (suggestion):
```suggestion
/// Preserve comments immediately preceding the version when bumping
```

Code after:
        .arg("--bump").arg("patch")
        .arg("--short"), @r"
    success: true
    exit_code: 0
    ----- stdout -----
    1.10.32

    ----- stderr -----
    Resolved 1 package in [TIME]
    Audited in [TIME]
    ");

    let pyproject = fs_err::read_to_string(&pyproject_toml)?;
    assert_snapshot!(
        pyproject,
    @r#"
    [project]
    name = "myproject"
    version = "1.10.32"
    requires-python = ">=3.12"
    "#
    );
    Ok(())
}

/// Preserve comments immediately preceding the version when bumping
#[test]
fn version_bump_preserves_preceding_comments() -> Result<()> {
    let context: TestContext = TestContext::new("3.12");

    let pyproject_toml = context.temp_dir.child("pyproject.toml");
    pyproject_toml.write_str(
        r#"
        [project]
        name = "hello-world"
        # pre-1: stays above version
        # pre-2: stays below pre-1
        version = "0.1.0" # eol: stays on same line
        # after-version: remains after version
        description = "Add your description here"
        "#,
    )?;

    // Bump patch version
    context
        .version()
        .arg("--bump")
        .arg("patch")
        .assert()
        .success();
Repository: astral-sh/uv
File: crates/uv/tests/it/python_upgrade.rs (Rust)

Code before:
    exit_code: 1
    ----- stdout -----

    ----- stderr -----
    error: `uv python upgrade` only accepts minor versions
    ");

    // Upgrade patch version
    uv_snapshot!(context.filters(), context.python_upgrade().arg("--preview").arg("3.10"), @r"
    success: true
    exit_code: 0
    ----- stdout -----

    ----- stderr -----
    Installed Python 3.10.18 in [TIME]
     + cpython-3.10.18-[PLATFORM] (python3.10)
    ");

    // Should be a no-op when already upgraded
    uv_snapshot!(context.filters(), context.python_upgrade().arg("--preview").arg("3.10"), @r"
    success: true
    exit_code: 0
    ----- stdout -----

    ----- stderr -----
    Python 3.10 is already on latest supported patch release
    ");

    // Should reinstall on `--reinstall`
    uv_snapshot!(context.filters(), context.python_upgrade().arg("--preview").arg("3.10").arg("--reinstall"), @r"
    success: true
    exit_code: 0
    ----- stdout -----

    ----- stderr -----
    Installed Python 3.10.18 in [TIME]
     ~ cpython-3.10.18-[PLATFORM] (python3.10)
    ");

    // Install an earlier pre-release version
    uv_snapshot!(context.filters(), context.python_install().arg("3.14.0rc2"), @r"
    success: true
    exit_code: 0
    ----- stdout -----

    ----- stderr -----
    Installed Python 3.14.0rc2 in [TIME]
     + cpython-3.14.0rc2-[PLATFORM] (python3.14)
    ");

    // Upgrade the pre-release version

Review comment (suggestion):
```suggestion
    Python 3.10 is already on the latest supported patch release
```


Code after:
    exit_code: 1
    ----- stdout -----

    ----- stderr -----
    error: `uv python upgrade` only accepts minor versions
    ");

    // Upgrade patch version
    uv_snapshot!(context.filters(), context.python_upgrade().arg("--preview").arg("3.10"), @r"
    success: true
    exit_code: 0
    ----- stdout -----

    ----- stderr -----
    Installed Python 3.10.18 in [TIME]
     + cpython-3.10.18-[PLATFORM] (python3.10)
    ");

    // Should be a no-op when already upgraded
    uv_snapshot!(context.filters(), context.python_upgrade().arg("--preview").arg("3.10"), @r"
    success: true
    exit_code: 0
    ----- stdout -----

    ----- stderr -----
    Python 3.10 is already on the latest supported patch release
    ");

    // Should reinstall on `--reinstall`
    uv_snapshot!(context.filters(), context.python_upgrade().arg("--preview").arg("3.10").arg("--reinstall"), @r"
    success: true
    exit_code: 0
    ----- stdout -----

    ----- stderr -----
    Installed Python 3.10.18 in [TIME]
     ~ cpython-3.10.18-[PLATFORM] (python3.10)
    ");

    // Install an earlier pre-release version
    uv_snapshot!(context.filters(), context.python_install().arg("3.14.0rc2"), @r"
    success: true
    exit_code: 0
    ----- stdout -----

    ----- stderr -----
    Installed Python 3.14.0rc2 in [TIME]
     + cpython-3.14.0rc2-[PLATFORM] (python3.14)
    ");

    // Upgrade the pre-release version
Repository: astral-sh/uv
File: crates/uv-client/src/error.rs (Rust)

Code before:
    pub title: Option<String>,

    /// The HTTP status code generated by the origin server for this occurrence of the problem.
    pub status: Option<u16>,

    /// A human-readable explanation specific to this occurrence of the problem.
    pub detail: Option<String>,

    /// A URI reference that identifies the specific occurrence of the problem.
    pub instance: Option<String>,

    /// Additional problem-specific extension fields
    #[serde(flatten)]
    pub extensions: std::collections::HashMap<String, serde_json::Value>,
}

/// Default problem type URI as per RFC 9457
fn default_problem_type() -> String {
    "about:blank".to_string()
}

impl ProblemDetails {
    /// Parse Problem Details from JSON bytes
    pub fn from_json(bytes: &[u8]) -> Result<Self, serde_json::Error> {
        serde_json::from_slice(bytes)
    }

    /// Get a human-readable description of the problem
    pub fn description(&self) -> String {
        if let Some(detail) = &self.detail {
            detail.clone()
        } else if let Some(title) = &self.title {
            title.clone()
        } else {
            format!("HTTP error {}", self.status.unwrap_or(0))
        }
    }
}

#[derive(Debug)]
pub struct Error {
    kind: Box<ErrorKind>,
    retries: u32,
}

impl Display for Error {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        if self.retries > 0 {
            write!(
                f,
                "Request failed after {retries} retries",

Review comment (suggestion):
My 0.02c would be for removing this, and just calling `serde_json::from_slice` directly wherever we use it 🙂 


Code after:
    pub title: Option<String>,

    /// The HTTP status code generated by the origin server for this occurrence of the problem.
    pub status: Option<u16>,

    /// A human-readable explanation specific to this occurrence of the problem.
    pub detail: Option<String>,

    /// A URI reference that identifies the specific occurrence of the problem.
    pub instance: Option<String>,
}

/// Default problem type URI as per RFC 9457
#[inline]
fn default_problem_type() -> String {
    "about:blank".to_string()
}

impl ProblemDetails {
    /// Get a human-readable description of the problem
    pub fn description(&self) -> Option<String> {
        match self {
            Self {
                title: Some(title),
                detail: Some(detail),
                ..
            } => Some(format!("Server message: {title}, {detail}")),
            Self {
                title: Some(title), ..
            } => Some(format!("Server message: {title}")),
            Self {
                detail: Some(detail),
                ..
            } => Some(format!("Server message: {detail}")),
            Self {
                status: Some(status),
                ..
            } => Some(format!("HTTP error {status}")),
            _ => None,
        }
    }
}

#[derive(Debug)]
pub struct Error {
    kind: Box<ErrorKind>,
    retries: u32,
}

impl Display for Error {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Repository: astral-sh/uv
File: crates/uv-client/src/error.rs (Rust)

Code before:
    /// Get a human-readable description of the problem
    pub fn description(&self) -> String {
        match self {
            Self {
                title: Some(title),
                detail: Some(detail),
                ..
            } => {
                format!("{title}: {detail}")
            }
            Self {
                title: Some(title), ..
            } => title.clone(),
            Self {
                detail: Some(detail),
                ..
            } => detail.clone(),
            Self {
                status: Some(status),
                ..
            } => {
                format!("HTTP error {status}")
            }
            _ => {
                // If no detail, title, or status is provided, return a generic message
                "An error occurred".to_string()
            }
        }
    }
}

#[derive(Debug)]
pub struct Error {
    kind: Box<ErrorKind>,
    retries: u32,
}

impl Display for Error {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        if self.retries > 0 {
            write!(
                f,
                "Request failed after {retries} retries",
                retries = self.retries
            )
        } else {
            Display::fmt(&self.kind, f)
        }
    }
}


Review comment (suggestion):
We should return `None` for this case and fall back to the default case in `WrappedReqwestError` instead of using our own string.

Code after:
    /// Get a human-readable description of the problem
    pub fn description(&self) -> Option<String> {
        match self {
            Self {
                title: Some(title),
                detail: Some(detail),
                ..
            } => Some(format!("Server message: {title}, {detail}")),
            Self {
                title: Some(title), ..
            } => Some(format!("Server message: {title}")),
            Self {
                detail: Some(detail),
                ..
            } => Some(format!("Server message: {detail}")),
            Self {
                status: Some(status),
                ..
            } => Some(format!("HTTP error {status}")),
            _ => None,
        }
    }
}

#[derive(Debug)]
pub struct Error {
    kind: Box<ErrorKind>,
    retries: u32,
}

impl Display for Error {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        if self.retries > 0 {
            write!(
                f,
                "Request failed after {retries} retries",
                retries = self.retries
            )
        } else {
            Display::fmt(&self.kind, f)
        }
    }
}

impl std::error::Error for Error {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        if self.retries > 0 {
            Some(&self.kind)
        } else {
            self.kind.source()
        }