Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions crates/uv-pep440/src/version_specifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,16 +554,9 @@ impl VersionSpecifier {
other.as_ref() >= this
}
Operator::GreaterThan => Self::greater_than(this, &other),
Operator::GreaterThanEqual => {
Self::greater_than(this, &other) || other.as_ref() >= this
}
Operator::LessThan => {
Self::less_than(this, &other)
&& !(version::compare_release(&this.release(), &other.release())
== Ordering::Equal
&& other.any_prerelease())
}
Operator::LessThanEqual => Self::less_than(this, &other) || other.as_ref() <= this,
Operator::GreaterThanEqual => other.as_ref() >= this,
Operator::LessThan => Self::less_than(this, &other),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a Reason some of these are Proper operators and others are named methods?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in #12873

Operator::LessThanEqual => other.as_ref() <= this,
}
}

Expand All @@ -572,13 +565,13 @@ impl VersionSpecifier {
return true;
}

// This special case is here so that, unless the specifier itself
// includes is a pre-release version, that we do not accept pre-release
// versions for the version mentioned in the specifier (e.g. <3.1 should
// not match 3.1.dev0, but should match 3.0.dev0).
if !this.any_prerelease()
&& other.is_pre()
&& version::compare_release(&this.release(), &other.release()) == Ordering::Equal
// The exclusive ordered comparison <V MUST NOT allow a pre-release of the specified
// version unless the specified version is itself a pre-release. E.g., <3.1 should
// not match 3.1.dev0, but should match both 3.0.dev0 and 3.0, while <3.1.dev1 does match
// 3.1.dev0, 3.0.dev0 and 3.0.
if version::compare_release(&this.release(), &other.release()) == Ordering::Equal
&& !this.any_prerelease()
&& other.any_prerelease()
{
return false;
}
Expand Down Expand Up @@ -1172,10 +1165,15 @@ mod tests {
("2.0.1", ">2"),
("2.1.post1", ">2"),
("2.1+local.version", ">2"),
("2.post2", ">2.post1"),
// Test the less than operation
("1", "<2"),
("2.0", "<2.1"),
("2.0.dev0", "<2.1"),
// https://github.com/astral-sh/uv/issues/12834
("0.1a1", "<0.1a2"),
("0.1dev1", "<0.1dev2"),
("0.1dev1", "<0.1a1"),
// Test the compatibility operation
("1", "~=1.0"),
("1.0.1", "~=1.0"),
Expand Down Expand Up @@ -1271,6 +1269,7 @@ mod tests {
("2.0c1.post1.dev1", ">2"),
("2.0rc1", ">2"),
("2.0", ">2"),
("2.post2", ">2"),
("2.0.post1", ">2"),
("2.0.post1.dev1", ">2"),
("2.0+local.version", ">2"),
Expand Down
Loading