mirror of https://github.com/pypa/pip
Cache results and remove unused implementation
This commit is contained in:
parent
a270ca5616
commit
01c9b6cf25
|
@ -1,5 +1,6 @@
|
||||||
from pip._vendor.six.moves import collections_abc # type: ignore
|
from pip._vendor.six.moves import collections_abc # type: ignore
|
||||||
|
|
||||||
|
from pip._internal.utils.compat import lru_cache
|
||||||
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
|
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
|
||||||
|
|
||||||
if MYPY_CHECK_RUNNING:
|
if MYPY_CHECK_RUNNING:
|
||||||
|
@ -96,10 +97,10 @@ class FoundCandidates(collections_abc.Sequence):
|
||||||
|
|
||||||
def __getitem__(self, index):
|
def __getitem__(self, index):
|
||||||
# type: (int) -> Candidate
|
# type: (int) -> Candidate
|
||||||
for i, value in enumerate(self):
|
# Implemented to satisfy the ABC check, This is not needed by the
|
||||||
if index == i:
|
# resolver, and should not be used by the provider either (for
|
||||||
return value
|
# performance reasons).
|
||||||
raise IndexError(index)
|
raise NotImplementedError("don't do this")
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
# type: () -> Iterator[Candidate]
|
# type: () -> Iterator[Candidate]
|
||||||
|
@ -109,10 +110,12 @@ class FoundCandidates(collections_abc.Sequence):
|
||||||
klass = _InstalledReplacesCandidatesIterator
|
klass = _InstalledReplacesCandidatesIterator
|
||||||
return klass(self._get_others, self._installed)
|
return klass(self._get_others, self._installed)
|
||||||
|
|
||||||
|
@lru_cache(maxsize=1)
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
# type: () -> int
|
# type: () -> int
|
||||||
return sum(1 for _ in self)
|
return sum(1 for _ in self)
|
||||||
|
|
||||||
|
@lru_cache(maxsize=1)
|
||||||
def __bool__(self):
|
def __bool__(self):
|
||||||
# type: () -> bool
|
# type: () -> bool
|
||||||
if self._prefers_installed and self._installed:
|
if self._prefers_installed and self._installed:
|
||||||
|
|
Loading…
Reference in New Issue