mirror of
https://github.com/python/cpython.git
synced 2025-10-25 18:54:53 +00:00
GH-128520: pathlib ABCs: add JoinablePath.__vfspath__() (#133437)
In the abstract interface of `JoinablePath`, replace `__str__()` with `__vfspath__()`. This frees user implementations of `JoinablePath` to implement `__str__()` however they like (or not at all.) Also add `pathlib._os.vfspath()`, which calls `__fspath__()` or `__vfspath__()`.
This commit is contained in:
parent
9f69a58623
commit
5dbd27db7d
8 changed files with 118 additions and 81 deletions
|
|
@ -97,7 +97,7 @@ class LocalPathInfo(PathInfo):
|
|||
__slots__ = ('_path', '_exists', '_is_dir', '_is_file', '_is_symlink')
|
||||
|
||||
def __init__(self, path):
|
||||
self._path = str(path)
|
||||
self._path = os.fspath(path)
|
||||
self._exists = None
|
||||
self._is_dir = None
|
||||
self._is_file = None
|
||||
|
|
@ -139,14 +139,12 @@ class ReadableLocalPath(_ReadablePath, LexicalPath):
|
|||
Simple implementation of a ReadablePath class for local filesystem paths.
|
||||
"""
|
||||
__slots__ = ('info',)
|
||||
__fspath__ = LexicalPath.__vfspath__
|
||||
|
||||
def __init__(self, *pathsegments):
|
||||
super().__init__(*pathsegments)
|
||||
self.info = LocalPathInfo(self)
|
||||
|
||||
def __fspath__(self):
|
||||
return str(self)
|
||||
|
||||
def __open_rb__(self, buffering=-1):
|
||||
return open(self, 'rb')
|
||||
|
||||
|
|
@ -163,9 +161,7 @@ class WritableLocalPath(_WritablePath, LexicalPath):
|
|||
"""
|
||||
|
||||
__slots__ = ()
|
||||
|
||||
def __fspath__(self):
|
||||
return str(self)
|
||||
__fspath__ = LexicalPath.__vfspath__
|
||||
|
||||
def __open_wb__(self, buffering=-1):
|
||||
return open(self, 'wb')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue