From 2c565916bc86242f54ab5600344e67f1bf9cbd21 Mon Sep 17 00:00:00 2001 From: barneygale Date: Wed, 12 Jul 2023 20:01:38 +0100 Subject: [PATCH] `_VirtualPath` --> `_PathBase` --- Lib/pathlib.py | 4 +-- Lib/test/test_pathlib.py | 30 +++++++++---------- ...3-07-03-20-23-56.gh-issue-89812.cFkDOE.rst | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Lib/pathlib.py b/Lib/pathlib.py index bed05295046e6a..1c08665c6d07f0 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -785,7 +785,7 @@ class PureWindowsPath(PurePath): # Filesystem-accessing classes -class _VirtualPath(PurePath): +class _PathBase(PurePath): """PurePath subclass for virtual filesystems, such as archives and remote storage. """ @@ -1379,7 +1379,7 @@ def as_uri(self): raise UnsupportedOperation(f"{type(self).__name__}.as_uri()") -class Path(_VirtualPath): +class Path(_PathBase): """PurePath subclass that can make system calls. Path represents a filesystem path but unlike PurePath, also offers diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py index 28581c493070d3..004ecba3f0b0ef 100644 --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -1573,8 +1573,8 @@ def test_group(self): # Tests for the virtual classes. # -class VirtualPathTest(PurePathTest): - cls = pathlib._VirtualPath +class PathBaseTest(PurePathTest): + cls = pathlib._PathBase def test_unsupported_operation(self): P = self.cls @@ -1632,9 +1632,9 @@ def test_as_bytes_common(self): self.assertRaises(TypeError, bytes, self.cls()) -class DummyVirtualPathIO(io.BytesIO): +class DummyPathIO(io.BytesIO): """ - Used by DummyVirtualPath to implement `open('w')` + Used by DummyPath to implement `open('w')` """ def __init__(self, files, path): @@ -1647,9 +1647,9 @@ def close(self): super().close() -class DummyVirtualPath(pathlib._VirtualPath): +class DummyPath(pathlib._PathBase): """ - Simple implementation of VirtualPath that keeps files and directories in + Simple implementation of PathBase that keeps files and directories in memory. """ _files = {} @@ -1691,7 +1691,7 @@ def open(self, mode='r', buffering=-1, encoding=None, elif mode == 'w': if parent not in self._directories: raise FileNotFoundError(errno.ENOENT, "File not found", parent) - stream = DummyVirtualPathIO(self._files, path) + stream = DummyPathIO(self._files, path) self._files[path] = b'' self._directories[parent].add(name) else: @@ -1724,10 +1724,10 @@ def mkdir(self, mode=0o777, parents=False, exist_ok=False): raise -class DummyVirtualPathTest(unittest.TestCase): - """Tests for VirtualPath methods that use stat(), open() and iterdir().""" +class DummyPathTest(unittest.TestCase): + """Tests for PathBase methods that use stat(), open() and iterdir().""" - cls = DummyVirtualPath + cls = DummyPath can_symlink = False # (BASE) @@ -2541,7 +2541,7 @@ def test_complex_symlinks_relative_dot_dot(self): self._check_complex_symlinks(os.path.join('dirA', '..')) -class DummyVirtualPathWithSymlinks(DummyVirtualPath): +class DummyPathWithSymlinks(DummyPath): def readlink(self): path = str(self) if path in self._symlinks: @@ -2556,8 +2556,8 @@ def symlink_to(self, target, target_is_directory=False): self._symlinks[str(self)] = str(target) -class DummyVirtualPathWithSymlinksTest(DummyVirtualPathTest): - cls = DummyVirtualPathWithSymlinks +class DummyPathWithSymlinksTest(DummyPathTest): + cls = DummyPathWithSymlinks can_symlink = True def setUp(self): @@ -2581,13 +2581,13 @@ def setUp(self): # Tests for the concrete classes. # -class PathTest(DummyVirtualPathTest): +class PathTest(DummyPathTest): """Tests for the FS-accessing functionalities of the Path classes.""" cls = pathlib.Path can_symlink = os_helper.can_symlink() def setUp(self): - # note: this must be kept in sync with `DummyVirtualPathTest.setUp()` + # note: this must be kept in sync with `DummyPathTest.setUp()` def cleanup(): os.chmod(join('dirE'), 0o777) os_helper.rmtree(BASE) diff --git a/Misc/NEWS.d/next/Library/2023-07-03-20-23-56.gh-issue-89812.cFkDOE.rst b/Misc/NEWS.d/next/Library/2023-07-03-20-23-56.gh-issue-89812.cFkDOE.rst index 2b100f09c67ad9..a4221fc4ca900b 100644 --- a/Misc/NEWS.d/next/Library/2023-07-03-20-23-56.gh-issue-89812.cFkDOE.rst +++ b/Misc/NEWS.d/next/Library/2023-07-03-20-23-56.gh-issue-89812.cFkDOE.rst @@ -1,2 +1,2 @@ -Add private ``pathlib._VirtualPath`` class, which provides experimental support +Add private ``pathlib._PathBase`` class, which provides experimental support for virtual filesystems, and may be made public in a future version of Python.