Skip to content

Commit 80609e8

Browse files
committed
Properly yield results from html5lib parsing
The earlier variant _returned_ an iterable object from a generator. This did not properly handle the fallback, resulting in the html5lib code path not being executed.
1 parent 6cc96c2 commit 80609e8

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

news/10846.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Properly handle links parsed by html5lib, when using ```--use-deprecated=html5lib``.

src/pip/_internal/index/collector.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,8 @@ def parse_links(page: "HTMLPage", use_deprecated_html5lib: bool) -> Iterable[Lin
343343
Parse an HTML document, and yield its anchor elements as Link objects.
344344
"""
345345
if use_deprecated_html5lib:
346-
return _parse_links_html5lib(page)
346+
yield from _parse_links_html5lib(page)
347+
return
347348

348349
parser = HTMLLinkParser()
349350
encoding = page.encoding or "utf-8"

tests/unit/test_collector.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,18 @@ def test_parse_links_caches_same_page_by_url() -> None:
539539
assert "pkg2" in parsed_links_3[0].url
540540

541541

542+
def test_parse_link_handles_deprecated_usage_properly() -> None:
543+
html = b'<a href="/pkg1-1.0.tar.gz"><a href="/pkg1-2.0.tar.gz">'
544+
url = "https://example.com/simple/"
545+
page = HTMLPage(html, encoding=None, url=url)
546+
547+
parsed_links = list(parse_links(page, use_deprecated_html5lib=True))
548+
549+
assert len(parsed_links) == 2
550+
assert "pkg1-1.0" in parsed_links[0].url
551+
assert "pkg1-2.0" in parsed_links[1].url
552+
553+
542554
@mock.patch("pip._internal.index.collector.raise_for_status")
543555
def test_request_http_error(
544556
mock_raise_for_status: mock.Mock, caplog: pytest.LogCaptureFixture

0 commit comments

Comments
 (0)