From 6e3d56897b159212813136b0126f82737105b924 Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Wed, 30 Sep 2020 21:36:15 +0800 Subject: [PATCH] Always return the installed version --- .../resolution/resolvelib/found_candidates.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/pip/_internal/resolution/resolvelib/found_candidates.py b/src/pip/_internal/resolution/resolvelib/found_candidates.py index 43591967f..c9b21727a 100644 --- a/src/pip/_internal/resolution/resolvelib/found_candidates.py +++ b/src/pip/_internal/resolution/resolvelib/found_candidates.py @@ -66,10 +66,19 @@ class _InstalledReplacesCandidatesIterator(collections_abc.Iterator): # type: () -> Candidate if self._others is None: self._others = self._get_others() - cand = next(self._others) - while cand.version in self._returned: + try: cand = next(self._others) - if self._installed and cand.version == self._installed.version: + while cand.version in self._returned: + cand = next(self._others) + if self._installed and cand.version == self._installed.version: + cand = self._installed + except StopIteration: + # Return the already-installed candidate as the last item if its + # version does not exist on the index. + if not self._installed: + raise + if self._installed.version in self._returned: + raise cand = self._installed self._returned.add(cand.version) return cand