GH-128520: Divide pathlib ABCs into three classes (#128523)

In the private pathlib ABCs, rename `PurePathBase` to `JoinablePath`, and
split `PathBase` into `ReadablePath` and `WritablePath`. This improves the
API fit for read-only virtual filesystems.

The split of `PathBase` entails a similar split of `CopyWorker` (implements
copying) and the test cases in `test_pathlib_abc`.

In a later patch, we'll make `WritablePath` inherit directly from
`JoinablePath` rather than `ReadablePath`. For a couple of reasons,
this isn't quite possible yet.
This commit is contained in:
Barney Gale 2025-01-11 19:27:47 +00:00 committed by GitHub
parent 0946ed25b5
commit 22a442181d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 317 additions and 307 deletions

View file

@ -75,7 +75,7 @@ class UnsupportedOperationTest(unittest.TestCase):
# Tests for the pure classes.
#
class PurePathTest(test_pathlib_abc.DummyPurePathTest):
class PurePathTest(test_pathlib_abc.DummyJoinablePathTest):
cls = pathlib.PurePath
# Make sure any symbolic links in the base test path are resolved.
@ -924,7 +924,7 @@ class PurePathSubclassTest(PurePathTest):
# Tests for the concrete classes.
#
class PathTest(test_pathlib_abc.DummyPathTest, PurePathTest):
class PathTest(test_pathlib_abc.DummyWritablePathTest, PurePathTest):
"""Tests for the FS-accessing functionalities of the Path classes."""
cls = pathlib.Path
can_symlink = os_helper.can_symlink()
@ -980,15 +980,15 @@ class PathTest(test_pathlib_abc.DummyPathTest, PurePathTest):
self.addCleanup(os_helper.rmtree, d)
return d
def test_matches_pathbase_docstrings(self):
path_names = {name for name in dir(pathlib._abc.PathBase) if name[0] != '_'}
def test_matches_writablepath_docstrings(self):
path_names = {name for name in dir(pathlib._abc.WritablePath) if name[0] != '_'}
for attr_name in path_names:
if attr_name == 'parser':
# On Windows, Path.parser is ntpath, but PathBase.parser is
# On Windows, Path.parser is ntpath, but WritablePath.parser is
# posixpath, and so their docstrings differ.
continue
our_attr = getattr(self.cls, attr_name)
path_attr = getattr(pathlib._abc.PathBase, attr_name)
path_attr = getattr(pathlib._abc.WritablePath, attr_name)
self.assertEqual(our_attr.__doc__, path_attr.__doc__)
def test_concrete_class(self):
@ -3019,7 +3019,7 @@ class PathTest(test_pathlib_abc.DummyPathTest, PurePathTest):
P('c:/').group()
class PathWalkTest(test_pathlib_abc.DummyPathWalkTest):
class PathWalkTest(test_pathlib_abc.DummyReadablePathWalkTest):
cls = pathlib.Path
base = PathTest.base
can_symlink = PathTest.can_symlink