From 6b7f60c1eaa840c2e933a0fb056ab46f99c991a5 Mon Sep 17 00:00:00 2001 From: konsti Date: Sat, 12 Apr 2025 22:57:06 +0200 Subject: [PATCH] Fix pre-release exclusive comparison operator in uv-pep440 (#12836) From PEP 440: > The exclusive ordered comparison = 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), + Operator::LessThanEqual => other.as_ref() <= this, } } @@ -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 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"), @@ -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"),