mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 13:25:00 +00:00
pep508: write x.y.* when serializing MarkerExpression
It's unclear to me whether this was intentional or not, but I realized that converting a MarkerExpression to a string treated EqualStar and NotEqualStar as Equal and NotEqual, respectively. I tweaked this to match the Display impl for VersionSpecifier. (Negation tests in the next commit cover this change.)
This commit is contained in:
parent
23c6cd774b
commit
da8a4a6faa
1 changed files with 12 additions and 8 deletions
|
@ -1489,19 +1489,23 @@ impl Display for MarkerExpression {
|
|||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
MarkerExpression::Version { key, specifier } => {
|
||||
write!(
|
||||
f,
|
||||
"{key} {} '{}'",
|
||||
specifier.operator(),
|
||||
specifier.version()
|
||||
)
|
||||
let (op, version) = (specifier.operator(), specifier.version());
|
||||
if op == &pep440_rs::Operator::EqualStar || op == &pep440_rs::Operator::NotEqualStar
|
||||
{
|
||||
return write!(f, "{key} {op} '{version}.*'");
|
||||
}
|
||||
write!(f, "{key} {op} '{version}'",)
|
||||
}
|
||||
MarkerExpression::VersionInverted {
|
||||
version,
|
||||
operator,
|
||||
operator: op,
|
||||
key,
|
||||
} => {
|
||||
write!(f, "'{version}' {operator} {key}")
|
||||
if op == &pep440_rs::Operator::EqualStar || op == &pep440_rs::Operator::NotEqualStar
|
||||
{
|
||||
return write!(f, "'{version}.*' {op} {key}");
|
||||
}
|
||||
write!(f, "'{version}' {op} {key}")
|
||||
}
|
||||
MarkerExpression::String {
|
||||
key,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue