From eb7c1ebd3cfc8a5688d4a6550056346bb90086ce Mon Sep 17 00:00:00 2001 From: Damian Shaw Date: Tue, 30 Apr 2024 01:29:13 -0400 Subject: [PATCH] Calculate candidate string versions only once in `get_applicable_candidates` --- src/pip/_internal/index/package_finder.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pip/_internal/index/package_finder.py b/src/pip/_internal/index/package_finder.py index 98ee6315567..f72de6f1dc1 100644 --- a/src/pip/_internal/index/package_finder.py +++ b/src/pip/_internal/index/package_finder.py @@ -452,6 +452,7 @@ def get_applicable_candidates( # Using None infers from the specifier instead. allow_prereleases = self._allow_all_prereleases or None specifier = self._specifier + candidates_and_versions = [(c, str(c.version)) for c in candidates] versions = { str(v) for v in specifier.filter( @@ -462,13 +463,13 @@ def get_applicable_candidates( # types. This way we'll use a str as a common data interchange # format. If we stop using the pkg_resources provided specifier # and start using our own, we can drop the cast to str(). - (str(c.version) for c in candidates), + (v for _, v in candidates_and_versions), prereleases=allow_prereleases, ) } # Again, converting version to str to deal with debundling. - applicable_candidates = [c for c in candidates if str(c.version) in versions] + applicable_candidates = [c for c, v in candidates_and_versions if v in versions] filtered_applicable_candidates = filter_unallowed_hashes( candidates=applicable_candidates,