Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid returning Some for narrowing no-ops #10705

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions crates/uv-resolver/src/python_requirement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ impl PythonRequirement {

/// Narrow the [`PythonRequirement`] to the given version, if it's stricter (i.e., greater)
/// than the current `Requires-Python` minimum.
///
/// Returns `None` if the given range is not narrower than the current range.
pub fn narrow(&self, target: &RequiresPythonRange) -> Option<Self> {
Some(Self {
exact: self.exact.clone(),
Expand Down
5 changes: 5 additions & 0 deletions crates/uv-resolver/src/requires_python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@ impl RequiresPython {
}

/// Narrow the [`RequiresPython`] by computing the intersection with the given range.
///
/// Returns `None` if the given range is not narrower than the current range.
pub fn narrow(&self, range: &RequiresPythonRange) -> Option<Self> {
if *range == self.range {
return None;
}
let lower = if range.0 >= self.range.0 {
Some(&range.0)
} else {
Expand Down
9 changes: 3 additions & 6 deletions crates/uv-resolver/src/resolver/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,17 +690,14 @@ mod tests {
}

/// Inside a fork whose marker's Python requirement is equal
/// to our Requires-Python means that narrowing produces a
/// result, but is unchanged from what we started with.
/// to our Requires-Python means that narrowing does not produce
/// a result.
#[test]
fn narrow_python_requirement_forking_no_op() {
let pyreq = python_requirement("3.10");
let resolver_env = ResolverEnvironment::universal(vec![])
.narrow_environment(marker("python_version >= '3.10'"));
assert_eq!(
resolver_env.narrow_python_requirement(&pyreq),
Some(python_requirement("3.10")),
);
assert_eq!(resolver_env.narrow_python_requirement(&pyreq), None);
}

/// In this test, we narrow a more relaxed requirement compared to the
Expand Down
Loading