Fix uv python pin 3.13t failure when parsing version for project requires check (#8056)

Closes https://github.com/astral-sh/uv/issues/7964

We can probably do some restructuring to avoid unwrapping here in the
future, but this just fixes the bug quick.
This commit is contained in:
Zanie Blue 2024-10-09 19:17:20 -05:00 committed by GitHub
parent 46a0ed7fa2
commit 82708944a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 43 additions and 4 deletions

View file

@ -1952,6 +1952,29 @@ impl VersionRequest {
| Self::Range(_, variant) => variant == &PythonVariant::Freethreaded,
}
}
/// Return a new [`VersionRequest`] with the [`PythonVariant`] if it has one.
///
/// This is useful for converting the string representation to pep440.
#[must_use]
pub fn without_python_variant(self) -> Self {
// TODO(zanieb): Replace this entire function with a utility that casts this to a version
// without using `VersionRequest::to_string`.
match self {
Self::Any | Self::Default => self,
Self::Major(major, _) => Self::Major(major, PythonVariant::Default),
Self::MajorMinor(major, minor, _) => {
Self::MajorMinor(major, minor, PythonVariant::Default)
}
Self::MajorMinorPatch(major, minor, patch, _) => {
Self::MajorMinorPatch(major, minor, patch, PythonVariant::Default)
}
Self::MajorMinorPrerelease(major, minor, prerelease, _) => {
Self::MajorMinorPrerelease(major, minor, prerelease, PythonVariant::Default)
}
Self::Range(specifiers, _) => Self::Range(specifiers, PythonVariant::Default),
}
}
}
impl FromStr for VersionRequest {