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:
Andrew Gallant 2024-07-11 14:02:38 -04:00 committed by Andrew Gallant
parent 23c6cd774b
commit da8a4a6faa

View file

@ -1489,19 +1489,23 @@ impl Display for MarkerExpression {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self { match self {
MarkerExpression::Version { key, specifier } => { MarkerExpression::Version { key, specifier } => {
write!( let (op, version) = (specifier.operator(), specifier.version());
f, if op == &pep440_rs::Operator::EqualStar || op == &pep440_rs::Operator::NotEqualStar
"{key} {} '{}'", {
specifier.operator(), return write!(f, "{key} {op} '{version}.*'");
specifier.version() }
) write!(f, "{key} {op} '{version}'",)
} }
MarkerExpression::VersionInverted { MarkerExpression::VersionInverted {
version, version,
operator, operator: op,
key, 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 { MarkerExpression::String {
key, key,