https://github.com/python/cpython/commit/4de4e654e592c4b3b1a073140b97ff7f373c7553
commit: 4de4e654e592c4b3b1a073140b97ff7f373c7553
branch: main
author: Barney Gale <[email protected]>
committer: barneygale <[email protected]>
date: 2024-01-14T23:06:04Z
summary:
Replace `pathlib._abc.PathModuleBase.splitroot()` with `splitdrive()` (#114065)
This allows users of the `pathlib-abc` PyPI package to use `posixpath` or
`ntpath` as a path module in versions of Python lacking
`os.path.splitroot()` (3.11 and before).
files:
M Lib/pathlib/_abc.py
M Lib/test/test_pathlib/test_pathlib_abc.py
diff --git a/Lib/pathlib/_abc.py b/Lib/pathlib/_abc.py
index 1fdca004d6b31f..48a6c218309385 100644
--- a/Lib/pathlib/_abc.py
+++ b/Lib/pathlib/_abc.py
@@ -165,12 +165,11 @@ def split(self, path):
"""
self._unsupported('split()')
- def splitroot(self, path):
- """Split the pathname path into a 3-item tuple (drive, root, tail),
- where *drive* is a device name or mount point, *root* is a string of
- separators after the drive, and *tail* is everything after the root.
- Any part may be empty."""
- self._unsupported('splitroot()')
+ def splitdrive(self, path):
+ """Split the path into a 2-item tuple (drive, tail), where *drive* is
+ a device name or mount point, and *tail* is everything after the
+ drive. Either part may be empty."""
+ self._unsupported('splitdrive()')
def normcase(self, path):
"""Normalize the case of the path."""
@@ -227,18 +226,17 @@ def as_posix(self):
@property
def drive(self):
"""The drive prefix (letter or UNC path), if any."""
- return self.pathmod.splitroot(self._raw_path)[0]
+ return self.pathmod.splitdrive(self.anchor)[0]
@property
def root(self):
"""The root of the path, if any."""
- return self.pathmod.splitroot(self._raw_path)[1]
+ return self.pathmod.splitdrive(self.anchor)[1]
@property
def anchor(self):
"""The concatenation of the drive and root, or ''."""
- drive, root, _ = self.pathmod.splitroot(self._raw_path)
- return drive + root
+ return self._stack[0]
@property
def name(self):
diff --git a/Lib/test/test_pathlib/test_pathlib_abc.py
b/Lib/test/test_pathlib/test_pathlib_abc.py
index c3c568c296e25c..f877c98b7678f4 100644
--- a/Lib/test/test_pathlib/test_pathlib_abc.py
+++ b/Lib/test/test_pathlib/test_pathlib_abc.py
@@ -27,7 +27,7 @@ def test_unsupported_operation(self):
m.sep
self.assertRaises(e, m.join, 'foo')
self.assertRaises(e, m.split, 'foo')
- self.assertRaises(e, m.splitroot, 'foo')
+ self.assertRaises(e, m.splitdrive, 'foo')
self.assertRaises(e, m.normcase, 'foo')
self.assertRaises(e, m.isabs, 'foo')
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]