mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Issue #27186: Add os.PathLike support to pathlib.
This adds support both to pathlib.PurePath's constructor as well as implementing __fspath__(). This removes the provisional status for pathlib. Initial patch by Dusty Phillips.
This commit is contained in:
parent
f41b82fb19
commit
568be63248
4 changed files with 56 additions and 14 deletions
|
@ -190,13 +190,18 @@ class _BasePurePathTest(object):
|
|||
P = self.cls
|
||||
p = P('a')
|
||||
self.assertIsInstance(p, P)
|
||||
class PathLike:
|
||||
def __fspath__(self):
|
||||
return "a/b/c"
|
||||
P('a', 'b', 'c')
|
||||
P('/a', 'b', 'c')
|
||||
P('a/b/c')
|
||||
P('/a/b/c')
|
||||
P(PathLike())
|
||||
self.assertEqual(P(P('a')), P('a'))
|
||||
self.assertEqual(P(P('a'), 'b'), P('a/b'))
|
||||
self.assertEqual(P(P('a'), P('b')), P('a/b'))
|
||||
self.assertEqual(P(P('a'), P('b'), P('c')), P(PathLike()))
|
||||
|
||||
def _check_str_subclass(self, *args):
|
||||
# Issue #21127: it should be possible to construct a PurePath object
|
||||
|
@ -384,6 +389,12 @@ class _BasePurePathTest(object):
|
|||
parts = p.parts
|
||||
self.assertEqual(parts, (sep, 'a', 'b'))
|
||||
|
||||
def test_fspath_common(self):
|
||||
P = self.cls
|
||||
p = P('a/b')
|
||||
self._check_str(p.__fspath__(), ('a/b',))
|
||||
self._check_str(os.fspath(p), ('a/b',))
|
||||
|
||||
def test_equivalences(self):
|
||||
for k, tuples in self.equivalences.items():
|
||||
canon = k.replace('/', self.sep)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue