mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 10:58:28 +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 {
|
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,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue