9
9
"""
10
10
11
11
import functools
12
- from typing import Callable , Iterator , Optional , Set , Tuple
12
+ from collections .abc import Sequence
13
+ from typing import TYPE_CHECKING , Any , Callable , Iterator , Optional , Set , Tuple
13
14
14
15
from pip ._vendor .packaging .version import _BaseVersion
15
- from pip ._vendor .six .moves import collections_abc # type: ignore
16
16
17
17
from .base import Candidate
18
18
19
19
IndexCandidateInfo = Tuple [_BaseVersion , Callable [[], Optional [Candidate ]]]
20
20
21
+ if TYPE_CHECKING :
22
+ SequenceCandidate = Sequence [Candidate ]
23
+ else :
24
+ # For compatibility: Python before 3.9 does not support using [] on the
25
+ # Sequence class.
26
+ #
27
+ # >>> from collections.abc import Sequence
28
+ # >>> Sequence[str]
29
+ # Traceback (most recent call last):
30
+ # File "<stdin>", line 1, in <module>
31
+ # TypeError: 'ABCMeta' object is not subscriptable
32
+ #
33
+ # TODO: Remove this block after dropping Python 3.8 support.
34
+ SequenceCandidate = Sequence
35
+
21
36
22
37
def _iter_built (infos : Iterator [IndexCandidateInfo ]) -> Iterator [Candidate ]:
23
38
"""Iterator for ``FoundCandidates``.
@@ -90,7 +105,7 @@ def _iter_built_with_inserted(
90
105
yield installed
91
106
92
107
93
- class FoundCandidates (collections_abc . Sequence ):
108
+ class FoundCandidates (SequenceCandidate ):
94
109
"""A lazy sequence to provide candidates to the resolver.
95
110
96
111
The intended usage is to return this from `find_matches()` so the resolver
@@ -111,7 +126,7 @@ def __init__(
111
126
self ._prefers_installed = prefers_installed
112
127
self ._incompatible_ids = incompatible_ids
113
128
114
- def __getitem__ (self , index : int ) -> Candidate :
129
+ def __getitem__ (self , index : Any ) -> Any :
115
130
# Implemented to satisfy the ABC check. This is not needed by the
116
131
# resolver, and should not be used by the provider either (for
117
132
# performance reasons).
0 commit comments