aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_pathlib/support/lexical_path.py
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2025-05-12 19:00:36 +0100
committerGitHub <noreply@github.com>2025-05-12 19:00:36 +0100
commit5dbd27db7d79af88fb3f9b47f8b80438a147d349 (patch)
tree44422a75ca931f679296bf630cf28a1842fad7bd /Lib/test/test_pathlib/support/lexical_path.py
parent9f69a58623bd01349a18ba0c7a9cb1dad6a51e8e (diff)
downloadcpython-5dbd27db7d79af88fb3f9b47f8b80438a147d349.tar.gz
cpython-5dbd27db7d79af88fb3f9b47f8b80438a147d349.zip
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__()`.
Diffstat (limited to 'Lib/test/test_pathlib/support/lexical_path.py')
-rw-r--r--Lib/test/test_pathlib/support/lexical_path.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/Lib/test/test_pathlib/support/lexical_path.py b/Lib/test/test_pathlib/support/lexical_path.py
index f29a521af9b..fd7fbf283a6 100644
--- a/Lib/test/test_pathlib/support/lexical_path.py
+++ b/Lib/test/test_pathlib/support/lexical_path.py
@@ -9,9 +9,10 @@ import posixpath
from . import is_pypi
if is_pypi:
- from pathlib_abc import _JoinablePath
+ from pathlib_abc import vfspath, _JoinablePath
else:
from pathlib.types import _JoinablePath
+ from pathlib._os import vfspath
class LexicalPath(_JoinablePath):
@@ -22,20 +23,20 @@ class LexicalPath(_JoinablePath):
self._segments = pathsegments
def __hash__(self):
- return hash(str(self))
+ return hash(vfspath(self))
def __eq__(self, other):
if not isinstance(other, LexicalPath):
return NotImplemented
- return str(self) == str(other)
+ return vfspath(self) == vfspath(other)
- def __str__(self):
+ def __vfspath__(self):
if not self._segments:
return ''
return self.parser.join(*self._segments)
def __repr__(self):
- return f'{type(self).__name__}({str(self)!r})'
+ return f'{type(self).__name__}({vfspath(self)!r})'
def with_segments(self, *pathsegments):
return type(self)(*pathsegments)