Do not allow local versions in Python version requests either (#7468)

Accidentally squashed https://github.com/astral-sh/uv/pull/7465 into the
wrong target.
This commit is contained in:
Zanie Blue 2024-09-17 11:10:38 -05:00 committed by GitHub
parent e31252e82e
commit 08a7c708d1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1718,8 +1718,8 @@ impl FromStr for VersionRequest {
// Split the release component if it uses the wheel tag format (e.g., `38`) // Split the release component if it uses the wheel tag format (e.g., `38`)
let version = split_wheel_tag_release_version(version); let version = split_wheel_tag_release_version(version);
// We dont allow post and dev versions here // We dont allow post, dev, or local versions here
if version.post().is_some() || version.dev().is_some() { if version.post().is_some() || version.dev().is_some() || !version.local().is_empty() {
return Err(Error::InvalidVersionRequest(s.to_string())); return Err(Error::InvalidVersionRequest(s.to_string()));
} }
@ -2323,6 +2323,13 @@ mod tests {
), ),
"Development version segments are not allowed" "Development version segments are not allowed"
); );
assert!(
matches!(
VersionRequest::from_str("3.12+local"),
Err(Error::InvalidVersionRequest(_))
),
"Local version segments are not allowed"
);
assert!( assert!(
matches!( matches!(
VersionRequest::from_str("3.12.post0"), VersionRequest::from_str("3.12.post0"),