|
16 | 16 | from pip._internal.utils.typing import MYPY_CHECK_RUNNING
|
17 | 17 |
|
18 | 18 | if MYPY_CHECK_RUNNING:
|
19 |
| - from typing import Callable, Iterator, Optional, Set |
20 |
| - |
21 |
| - from pip._vendor.packaging.version import _BaseVersion |
| 19 | + from typing import Callable, Iterator, Optional |
22 | 20 |
|
23 | 21 | from .base import Candidate
|
24 | 22 |
|
25 | 23 |
|
26 |
| -def _deduplicated_by_version(candidates): |
27 |
| - # type: (Iterator[Candidate]) -> Iterator[Candidate] |
28 |
| - returned = set() # type: Set[_BaseVersion] |
29 |
| - for candidate in candidates: |
30 |
| - if candidate.version in returned: |
31 |
| - continue |
32 |
| - returned.add(candidate.version) |
33 |
| - yield candidate |
34 |
| - |
35 |
| - |
36 | 24 | def _insert_installed(installed, others):
|
37 | 25 | # type: (Candidate, Iterator[Candidate]) -> Iterator[Candidate]
|
38 | 26 | """Iterator for ``FoundCandidates``.
|
@@ -86,12 +74,15 @@ def __getitem__(self, index):
|
86 | 74 | def __iter__(self):
|
87 | 75 | # type: () -> Iterator[Candidate]
|
88 | 76 | if not self._installed:
|
89 |
| - candidates = self._get_others() |
90 |
| - elif self._prefers_installed: |
91 |
| - candidates = itertools.chain([self._installed], self._get_others()) |
92 |
| - else: |
93 |
| - candidates = _insert_installed(self._installed, self._get_others()) |
94 |
| - return _deduplicated_by_version(candidates) |
| 77 | + return self._get_others() |
| 78 | + others = ( |
| 79 | + candidate |
| 80 | + for candidate in self._get_others() |
| 81 | + if candidate.version != self._installed.version |
| 82 | + ) |
| 83 | + if self._prefers_installed: |
| 84 | + return itertools.chain([self._installed], others) |
| 85 | + return _insert_installed(self._installed, others) |
95 | 86 |
|
96 | 87 | def __len__(self):
|
97 | 88 | # type: () -> int
|
|
0 commit comments