From b43de79275271995bb3179d03d0f1b50f61dea00 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 12 Jun 2024 20:48:59 -0400 Subject: [PATCH] Fix incorrect parsing of requested Python version as empty version specifiers (#4289) Before 0.2.10 we would parse `--python=python` as an executable name. After https://github.com/astral-sh/uv/pull/4214, we started treating this as a Python version range request (with an empty version range). This is not entirely unreasonable, but it was an unexpected regression and I don't think `VersionRequest` should support empty ranges in its `from_str` implementation without more consideration. --- crates/uv-toolchain/src/discovery.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/uv-toolchain/src/discovery.rs b/crates/uv-toolchain/src/discovery.rs index 0a1f311dabdd..e588c38ec98e 100644 --- a/crates/uv-toolchain/src/discovery.rs +++ b/crates/uv-toolchain/src/discovery.rs @@ -1237,6 +1237,9 @@ impl FromStr for VersionRequest { Ok(selector) // e.g. `>=3.12.1,<3.12` } else if let Ok(specifiers) = VersionSpecifiers::from_str(s) { + if specifiers.is_empty() { + return Err(Error::InvalidVersionRequest(s.to_string())); + } Ok(Self::Range(specifiers)) } else { Err(Error::InvalidVersionRequest(s.to_string()))