Skip to content

Commit

Permalink
Lazy-evaluate candidates with installed inserted
Browse files Browse the repository at this point in the history
I don't really know why we didn't do this before, but the implementation
seems to match the description in the docstring.
  • Loading branch information
uranusjr committed Dec 15, 2020
1 parent c1dc7a8 commit cf5824a
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/pip/_internal/resolution/resolvelib/found_candidates.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import itertools
import operator

from pip._vendor.six.moves import collections_abc # type: ignore

Expand Down Expand Up @@ -31,19 +30,11 @@ def _insert_installed(installed, others):
This iterator is used when the resolver prefers to upgrade an
already-installed package. Candidates from index are returned in their
normal ordering, except replaced when the version is already installed.
Since candidates from index are already sorted by reverse version order,
`sorted()` here would keep the ordering mostly intact, only shuffling the
already-installed candidate into the correct position. We put the already-
installed candidate in front of those from the index, so it's put in front
after sorting due to Python sorting's stableness guarentee.
"""
candidates = sorted(
itertools.chain([installed], others),
key=operator.attrgetter("version"),
reverse=True,
)
return iter(candidates)
for candidate in others:
if candidate.version == installed.version:
candidate = installed
yield candidate


class FoundCandidates(collections_abc.Sequence):
Expand Down

0 comments on commit cf5824a

Please sign in to comment.