Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

GH-128520: pathlib ABCs: tweak protocol for virtual path strings#134104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
barneygale wants to merge1 commit intopython:main
base:main
Choose a base branch
Loading
frombarneygale:vfspath-drop-fspath
Draft
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletionsLib/pathlib/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -188,9 +188,6 @@ def __reduce__(self):
def __repr__(self):
return "{}({!r})".format(self.__class__.__name__, self.as_posix())

def __fspath__(self):
return str(self)

def __bytes__(self):
"""Return the bytes representation of the path. This is only
recommended to use under Unix."""
Expand DownExpand Up@@ -259,6 +256,9 @@ def __str__(self):
self._tail) or '.'
return self._str

__fspath__ = __str__
__vfspath__ = __str__

@classmethod
def _format_parsed_parts(cls, drv, root, tail):
if drv or root:
Expand Down
16 changes: 5 additions & 11 deletionsLib/pathlib/_os.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
return cls.__vfspath__(obj)
except AttributeError:
if hasattr(path_type, '__vfspath__'):
if hasattr(cls, '__vfspath__'):
raise

raise TypeError("expected str, bytes, os.PathLike or JoinablePath "
"object, not " + path_type.__name__)
raise TypeError("expected JoinablePath object, not " + cls.__name__)


def ensure_distinct_paths(source, target):
Expand Down
2 changes: 1 addition & 1 deletionLib/test/test_pathlib/support/zip_path.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -334,4 +334,4 @@ def symlink_to(self, target, target_is_directory=False):
zinfo.external_attr = stat.S_IFLNK << 16
if target_is_directory:
zinfo.external_attr |= 0x10
self.zip_file.writestr(zinfo,vfspath(target))
self.zip_file.writestr(zinfo, target)
Loading

[8]ページ先頭

©2009-2025 Movatter.jp