Skip to content

Commit

Permalink
Avoid returning Some for narrowing no-ops
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jan 17, 2025
1 parent dce7b9d commit c4a45e4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
3 changes: 3 additions & 0 deletions crates/uv-resolver/src/requires_python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ impl RequiresPython {

/// Narrow the [`RequiresPython`] by computing the intersection with the given 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

0 comments on commit c4a45e4

Please sign in to comment.