From b6489806258b6af46c133db756ec041794548924 Mon Sep 17 00:00:00 2001 From: konsti Date: Mon, 14 Apr 2025 10:10:34 +0200 Subject: [PATCH] Address #12836 review comment (#12873) Inline single use methods --- crates/uv-pep440/src/version_specifier.rs | 84 +++++++++++------------ 1 file changed, 40 insertions(+), 44 deletions(-) diff --git a/crates/uv-pep440/src/version_specifier.rs b/crates/uv-pep440/src/version_specifier.rs index 210f1969f..75f1286a0 100644 --- a/crates/uv-pep440/src/version_specifier.rs +++ b/crates/uv-pep440/src/version_specifier.rs @@ -553,55 +553,51 @@ impl VersionSpecifier { // pypa/packaging disagrees: https://github.com/pypa/packaging/issues/617 other.as_ref() >= this } - Operator::GreaterThan => Self::greater_than(this, &other), + Operator::GreaterThan => { + if other.epoch() > this.epoch() { + return true; + } + + if version::compare_release(&this.release(), &other.release()) == Ordering::Equal { + // This special case is here so that, unless the specifier itself + // includes is a post-release version, that we do not accept + // post-release versions for the version mentioned in the specifier + // (e.g. >3.1 should not match 3.0.post0, but should match 3.2.post0). + if !this.is_post() && other.is_post() { + return false; + } + + // We already checked that self doesn't have a local version + if other.is_local() { + return false; + } + } + + other.as_ref() > this + } Operator::GreaterThanEqual => other.as_ref() >= this, - Operator::LessThan => Self::less_than(this, &other), + Operator::LessThan => { + if other.epoch() < this.epoch() { + return true; + } + + // The exclusive ordered comparison other.as_ref() <= this, } } - fn less_than(this: &Version, other: &Version) -> bool { - if other.epoch() < this.epoch() { - return true; - } - - // The exclusive ordered comparison bool { - if other.epoch() > this.epoch() { - return true; - } - - if version::compare_release(&this.release(), &other.release()) == Ordering::Equal { - // This special case is here so that, unless the specifier itself - // includes is a post-release version, that we do not accept - // post-release versions for the version mentioned in the specifier - // (e.g. >3.1 should not match 3.0.post0, but should match 3.2.post0). - if !this.is_post() && other.is_post() { - return false; - } - - // We already checked that self doesn't have a local version - if other.is_local() { - return false; - } - } - - other > this - } - /// Whether this version specifier rejects versions below a lower cutoff. pub fn has_lower_bound(&self) -> bool { match self.operator() {