Skip to content

Commit

Permalink
Calculate candidate string versions only once in `get_applicable_cand…
Browse files Browse the repository at this point in the history
…idates`
  • Loading branch information
notatallshaw committed Apr 30, 2024
1 parent 9ef0fdf commit eb7c1eb
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/pip/_internal/index/package_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down

0 comments on commit eb7c1eb

Please sign in to comment.