mirror of
https://github.com/python/cpython.git
synced 2025-10-31 21:51:50 +00:00
GH-128520: pathlib ABCs: tweak protocol for virtual path strings (#134104)
Adjust `pathlib._os.vfspath()` so that it doesn't try `os.fsdecode()`. I don't know that supporting `os.PathLike` arguments is a good idea, so it's best to leave it out for now.
This commit is contained in:
parent
10a925c86d
commit
2bd4ff0700
3 changed files with 11 additions and 17 deletions
|
|
@ -210,24 +210,18 @@ def magic_open(path, mode='r', buffering=-1, encoding=None, errors=None,
|
|||
raise TypeError(f"{cls.__name__} can't be opened with mode {mode!r}")
|
||||
|
||||
|
||||
def vfspath(path):
|
||||
def vfspath(obj):
|
||||
"""
|
||||
Return the string representation of a virtual path object.
|
||||
"""
|
||||
cls = type(obj)
|
||||
try:
|
||||
return os.fsdecode(path)
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
path_type = type(path)
|
||||
try:
|
||||
return path_type.__vfspath__(path)
|
||||
vfspath_method = cls.__vfspath__
|
||||
except AttributeError:
|
||||
if hasattr(path_type, '__vfspath__'):
|
||||
raise
|
||||
|
||||
raise TypeError("expected str, bytes, os.PathLike or JoinablePath "
|
||||
"object, not " + path_type.__name__)
|
||||
cls_name = cls.__name__
|
||||
raise TypeError(f"expected JoinablePath object, not {cls_name}") from None
|
||||
else:
|
||||
return vfspath_method(obj)
|
||||
|
||||
|
||||
def ensure_distinct_paths(source, target):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue