Skip to content

Commit b208169

Browse files
fix test failures
1 parent 9cf718c commit b208169

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/pip/_internal/index/collector.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,23 @@
88
import mimetypes
99
import os
1010
from collections import OrderedDict
11-
from functools import lru_cache
11+
12+
try:
13+
from functools import lru_cache
14+
except ImportError:
15+
# Only works for single-argument functions.
16+
def lru_cache(*args, **kwargs):
17+
cache = {}
18+
def wrapper(fn):
19+
def wrapped(arg):
20+
value = cache.get(arg, None)
21+
if value is not None:
22+
return value
23+
value = fn(arg)
24+
cache[arg] = value
25+
return value
26+
return wrapped
27+
return wrapper
1228

1329
from pip._vendor import html5lib, requests
1430
from pip._vendor.distlib.compat import unescape
@@ -273,7 +289,6 @@ def parse_links(page):
273289
"""
274290
Parse an HTML document, and yield its anchor elements as Link objects.
275291
"""
276-
277292
document = html5lib.parse(
278293
page.content,
279294
transport_encoding=page.encoding,
@@ -282,7 +297,6 @@ def parse_links(page):
282297

283298
url = page.url
284299
base_url = _determine_base_url(document, url)
285-
all_links = []
286300
for anchor in document.findall(".//a"):
287301
link = _create_link_from_element(
288302
anchor,

tests/unit/test_collector.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,12 @@ def test_parse_links_caches_same_page():
290290
page_1 = HTMLPage(
291291
html_bytes,
292292
encoding=None,
293-
url='https://example.com/simple/',
293+
url='https://example.com/some-find-links-url/',
294294
)
295295
page_2 = HTMLPage(
296296
html_bytes,
297297
encoding=None,
298-
url='https://example.com/simple/',
298+
url='https://example.com/some-find-links-url/',
299299
)
300300

301301
with mock.patch("pip._internal.index.collector.html5lib.parse") as mock_parse:

0 commit comments

Comments
 (0)