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 {
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,