Address #12836 review comment (#12873)

Inline single use methods
This commit is contained in:
konsti 2025-04-14 10:10:34 +02:00 committed by GitHub
parent 2a02c600c8
commit b648980625
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 40 additions and 44 deletions

View File

@ -553,33 +553,7 @@ impl VersionSpecifier {
// pypa/packaging disagrees: https://github.com/pypa/packaging/issues/617 // pypa/packaging disagrees: https://github.com/pypa/packaging/issues/617
other.as_ref() >= this other.as_ref() >= this
} }
Operator::GreaterThan => Self::greater_than(this, &other), Operator::GreaterThan => {
Operator::GreaterThanEqual => other.as_ref() >= this,
Operator::LessThan => Self::less_than(this, &other),
Operator::LessThanEqual => other.as_ref() <= this,
}
}
fn less_than(this: &Version, other: &Version) -> bool {
if other.epoch() < this.epoch() {
return true;
}
// 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;
}
other < this
}
fn greater_than(this: &Version, other: &Version) -> bool {
if other.epoch() > this.epoch() { if other.epoch() > this.epoch() {
return true; return true;
} }
@ -599,7 +573,29 @@ impl VersionSpecifier {
} }
} }
other > this other.as_ref() > this
}
Operator::GreaterThanEqual => other.as_ref() >= this,
Operator::LessThan => {
if other.epoch() < this.epoch() {
return true;
}
// 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;
}
other.as_ref() < this
}
Operator::LessThanEqual => other.as_ref() <= this,
}
} }
/// Whether this version specifier rejects versions below a lower cutoff. /// Whether this version specifier rejects versions below a lower cutoff.