GH-128520: Subclass abc.ABC in pathlib._abc (#128745)

Convert `JoinablePath`, `ReadablePath` and `WritablePath` to real ABCs
derived from `abc.ABC`.

Make `JoinablePath.parser` abstract, rather than defaulting to `posixpath`.

Register `PurePath` and `Path` as virtual subclasses of the ABCs rather
than deriving. This avoids a hit to path object instantiation performance.

No change of behaviour in the public (non-abstract) classes.
This commit is contained in:
Barney Gale 2025-02-16 00:37:26 +00:00 committed by GitHub
parent 359c7dde3b
commit a7d41a8947
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 125 additions and 49 deletions

View file

@ -75,7 +75,7 @@ def test_is_notimplemented(self):
# Tests for the pure classes.
#
class PurePathTest(test_pathlib_abc.DummyJoinablePathTest):
class PurePathTest(test_pathlib_abc.JoinablePathTest):
cls = pathlib.PurePath
# Make sure any symbolic links in the base test path are resolved.
@ -1002,7 +1002,7 @@ class cls(pathlib.PurePath):
# Tests for the concrete classes.
#
class PathTest(test_pathlib_abc.DummyRWPathTest, PurePathTest):
class PathTest(test_pathlib_abc.RWPathTest, PurePathTest):
"""Tests for the FS-accessing functionalities of the Path classes."""
cls = pathlib.Path
can_symlink = os_helper.can_symlink()
@ -3119,7 +3119,7 @@ def test_group_windows(self):
P('c:/').group()
class PathWalkTest(test_pathlib_abc.DummyReadablePathWalkTest):
class PathWalkTest(test_pathlib_abc.ReadablePathWalkTest):
cls = pathlib.Path
base = PathTest.base
can_symlink = PathTest.can_symlink