Skip to content

Commit dc20f20

Browse files
committed
1 parent dd24396 commit dc20f20

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

news/13423.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix remaining test failures in Python 3.14 by adjusting ``path_to_url`` and similar functions.

src/pip/_internal/models/link.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import os
77
import posixpath
88
import re
9+
import sys
910
import urllib.parse
1011
from collections.abc import Mapping
1112
from dataclasses import dataclass
@@ -131,7 +132,11 @@ def _clean_file_url_path(part: str) -> str:
131132
# should not be quoted. On Linux where drive letters do not
132133
# exist, the colon should be quoted. We rely on urllib.request
133134
# to do the right thing here.
134-
return urllib.request.pathname2url(urllib.request.url2pathname(part))
135+
ret = urllib.request.pathname2url(urllib.request.url2pathname(part))
136+
if sys.version_info >= (3, 14):
137+
# https://discuss.python.org/t/pathname2url-changes-in-python-3-14-breaking-pip-tests/97091
138+
ret = ret.removeprefix("//")
139+
return ret
135140

136141

137142
# percent-encoded: /

src/pip/_internal/utils/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def path_to_url(path: str) -> str:
1212
quoted path parts.
1313
"""
1414
path = os.path.normpath(os.path.abspath(path))
15-
url = urllib.parse.urljoin("file:", urllib.request.pathname2url(path))
15+
url = urllib.parse.urljoin("file://", urllib.request.pathname2url(path))
1616
return url
1717

1818

tests/unit/test_urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
def test_path_to_url_unix() -> None:
1212
assert path_to_url("/tmp/file") == "file:///tmp/file"
1313
path = os.path.join(os.getcwd(), "file")
14-
assert path_to_url("file") == "file://" + urllib.request.pathname2url(path)
14+
assert path_to_url("file") == "file://" + path
1515

1616

1717
@pytest.mark.skipif("sys.platform != 'win32'")

0 commit comments

Comments
 (0)