From da8a4a6faa46481d3779c1ea6a4faacb8c8464c5 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Thu, 11 Jul 2024 14:02:38 -0400 Subject: [PATCH] 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.) --- crates/pep508-rs/src/marker.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/crates/pep508-rs/src/marker.rs b/crates/pep508-rs/src/marker.rs index cef05fde5..9c1a4c69f 100644 --- a/crates/pep508-rs/src/marker.rs +++ b/crates/pep508-rs/src/marker.rs @@ -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,