Skip to content

Commit cfb2487

Browse files
authored
Merge branch 'main' into docs-readline-repl
2 parents f94df93 + 2bd4ff0 commit cfb2487

File tree

6 files changed

+22
-18
lines changed

6 files changed

+22
-18
lines changed

Lib/pathlib/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,6 @@ def __reduce__(self):
188188
def __repr__(self):
189189
return "{}({!r})".format(self.__class__.__name__, self.as_posix())
190190

191-
def __fspath__(self):
192-
return str(self)
193-
194191
def __bytes__(self):
195192
"""Return the bytes representation of the path. This is only
196193
recommended to use under Unix."""
@@ -259,6 +256,9 @@ def __str__(self):
259256
self._tail) or '.'
260257
return self._str
261258

259+
__fspath__ = __str__
260+
__vfspath__ = __str__
261+
262262
@classmethod
263263
def _format_parsed_parts(cls, drv, root, tail):
264264
if drv or root:

Lib/pathlib/_os.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -210,24 +210,18 @@ def magic_open(path, mode='r', buffering=-1, encoding=None, errors=None,
210210
raise TypeError(f"{cls.__name__} can't be opened with mode {mode!r}")
211211

212212

213-
def vfspath(path):
213+
def vfspath(obj):
214214
"""
215215
Return the string representation of a virtual path object.
216216
"""
217+
cls = type(obj)
217218
try:
218-
return os.fsdecode(path)
219-
except TypeError:
220-
pass
221-
222-
path_type = type(path)
223-
try:
224-
return path_type.__vfspath__(path)
219+
vfspath_method = cls.__vfspath__
225220
except AttributeError:
226-
if hasattr(path_type, '__vfspath__'):
227-
raise
228-
229-
raise TypeError("expected str, bytes, os.PathLike or JoinablePath "
230-
"object, not " + path_type.__name__)
221+
cls_name = cls.__name__
222+
raise TypeError(f"expected JoinablePath object, not {cls_name}") from None
223+
else:
224+
return vfspath_method(obj)
231225

232226

233227
def ensure_distinct_paths(source, target):

Lib/test/test_pathlib/support/zip_path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,4 +334,4 @@ def symlink_to(self, target, target_is_directory=False):
334334
zinfo.external_attr = stat.S_IFLNK << 16
335335
if target_is_directory:
336336
zinfo.external_attr |= 0x10
337-
self.zip_file.writestr(zinfo, vfspath(target))
337+
self.zip_file.writestr(zinfo, target)

Lib/test/test_urllib.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,6 +1590,10 @@ def test_url2pathname_resolve_host(self):
15901590
def test_url2pathname_win(self):
15911591
fn = urllib.request.url2pathname
15921592
self.assertEqual(fn('/C:/'), 'C:\\')
1593+
self.assertEqual(fn('//C:'), 'C:')
1594+
self.assertEqual(fn('//C:/'), 'C:\\')
1595+
self.assertEqual(fn('//C:\\'), 'C:\\')
1596+
self.assertEqual(fn('//C:80/'), 'C:80\\')
15931597
self.assertEqual(fn("///C|"), 'C:')
15941598
self.assertEqual(fn("///C:"), 'C:')
15951599
self.assertEqual(fn('///C:/'), 'C:\\')

Lib/urllib/request.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1660,7 +1660,10 @@ def url2pathname(url, *, require_scheme=False, resolve_host=False):
16601660
if scheme != 'file':
16611661
raise URLError("URL is missing a 'file:' scheme")
16621662
if os.name == 'nt':
1663-
if not _is_local_authority(authority, resolve_host):
1663+
if authority[1:2] == ':':
1664+
# e.g. file://c:/file.txt
1665+
url = authority + url
1666+
elif not _is_local_authority(authority, resolve_host):
16641667
# e.g. file://server/share/file.txt
16651668
url = '//' + authority + url
16661669
elif url[:3] == '///':
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix handling of file URLs with a Windows drive letter in the URL authority
2+
by :func:`urllib.request.url2pathname`. This fixes a regression in earlier
3+
pre-releases of Python 3.14.

0 commit comments

Comments
 (0)