From c4a45e4454ca123001a79062fd8a3e1c28ded2d8 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 16 Jan 2025 23:49:14 -0500 Subject: [PATCH] Avoid returning Some for narrowing no-ops --- crates/uv-resolver/src/requires_python.rs | 3 +++ crates/uv-resolver/src/resolver/environment.rs | 9 +++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/uv-resolver/src/requires_python.rs b/crates/uv-resolver/src/requires_python.rs index 7bc7eb428819..0784f807e130 100644 --- a/crates/uv-resolver/src/requires_python.rs +++ b/crates/uv-resolver/src/requires_python.rs @@ -116,6 +116,9 @@ impl RequiresPython { /// Narrow the [`RequiresPython`] by computing the intersection with the given range. pub fn narrow(&self, range: &RequiresPythonRange) -> Option { + if *range == self.range { + return None; + } let lower = if range.0 >= self.range.0 { Some(&range.0) } else { diff --git a/crates/uv-resolver/src/resolver/environment.rs b/crates/uv-resolver/src/resolver/environment.rs index 5d2914985f10..401b308e61d9 100644 --- a/crates/uv-resolver/src/resolver/environment.rs +++ b/crates/uv-resolver/src/resolver/environment.rs @@ -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