|
19 | 19 |
|
20 | 20 | from pip._internal.models.link import Link
|
21 | 21 | from pip._internal.models.search_scope import SearchScope
|
| 22 | +from pip._internal.utils.compat import lru_cache |
22 | 23 | from pip._internal.utils.filetypes import ARCHIVE_EXTENSIONS
|
23 | 24 | from pip._internal.utils.misc import pairwise, redact_auth_from_url
|
24 | 25 | from pip._internal.utils.typing import MYPY_CHECK_RUNNING
|
|
29 | 30 | from optparse import Values
|
30 | 31 | from typing import (
|
31 | 32 | Callable, Iterable, List, MutableMapping, Optional,
|
32 |
| - Protocol, Sequence, Tuple, TypeVar, Union, |
| 33 | + Sequence, Tuple, Union, |
33 | 34 | )
|
34 | 35 | import xml.etree.ElementTree
|
35 | 36 |
|
|
40 | 41 | HTMLElement = xml.etree.ElementTree.Element
|
41 | 42 | ResponseHeaders = MutableMapping[str, str]
|
42 | 43 |
|
43 |
| - # Used in the @lru_cache polyfill. |
44 |
| - F = TypeVar('F') |
45 |
| - |
46 |
| - class LruCache(Protocol): |
47 |
| - def __call__(self, maxsize=None): |
48 |
| - # type: (Optional[int]) -> Callable[[F], F] |
49 |
| - raise NotImplementedError |
50 |
| - |
51 | 44 |
|
52 | 45 | logger = logging.getLogger(__name__)
|
53 | 46 |
|
54 | 47 |
|
55 |
| -# Fallback to noop_lru_cache in Python 2 |
56 |
| -# TODO: this can be removed when python 2 support is dropped! |
57 |
| -def noop_lru_cache(maxsize=None): |
58 |
| - # type: (Optional[int]) -> Callable[[F], F] |
59 |
| - def _wrapper(f): |
60 |
| - # type: (F) -> F |
61 |
| - return f |
62 |
| - return _wrapper |
63 |
| - |
64 |
| - |
65 |
| -_lru_cache = getattr(functools, "lru_cache", noop_lru_cache) # type: LruCache |
66 |
| - |
67 |
| - |
68 | 48 | def _match_vcs_scheme(url):
|
69 | 49 | # type: (str) -> Optional[str]
|
70 | 50 | """Look for VCS schemes in the URL.
|
@@ -334,7 +314,7 @@ def with_cached_html_pages(
|
334 | 314 | `page` has `page.cache_link_parsing == False`.
|
335 | 315 | """
|
336 | 316 |
|
337 |
| - @_lru_cache(maxsize=None) |
| 317 | + @lru_cache(maxsize=None) |
338 | 318 | def wrapper(cacheable_page):
|
339 | 319 | # type: (CacheablePageContent) -> List[Link]
|
340 | 320 | return list(fn(cacheable_page.page))
|
|
0 commit comments