cpython: 03bbee2b0d28 (original) (raw)

--- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -919,7 +919,7 @@ call fails (for example because the path to an existing file or directory, it will be unconditionally replaced. -.. method:: Path.resolve() +.. method:: Path.resolve(strict=False) Make the path absolute, resolving any symlinks. A new path object is returned:: @@ -936,10 +936,14 @@ call fails (for example because the path >>> p.resolve() PosixPath('/home/antoine/pathlib/setup.py')

.. method:: Path.rglob(pattern)

--- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -178,12 +178,26 @@ class _WindowsFlavour(_Flavour): def casefold_parts(self, parts): return [p.lower() for p in parts]

@@ -285,7 +299,7 @@ class _PosixFlavour(_Flavour): def casefold_parts(self, parts): return parts

@@ -315,7 +329,10 @@ class _PosixFlavour(_Flavour): target = accessor.readlink(newpath) except OSError as e: if e.errno != EINVAL:

@@ -1092,7 +1109,7 @@ class Path(PurePath): obj._init(template=self) return obj

@@ -1100,7 +1117,7 @@ class Path(PurePath): """ if self._closed: self._raise_closed()

--- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -1486,8 +1486,8 @@ class _BasePathTest(object): self.assertEqual(set(p.glob("../xyzzy")), set())

# this can be used to check both relative and absolute resolutions @@ -1498,8 +1498,17 @@ class _BasePathTest(object): P = self.cls p = P(BASE, 'foo') with self.assertRaises(OSError) as cm:

@@ -1509,6 +1518,18 @@ class _BasePathTest(object): self._check_resolve_relative(p, P(BASE, 'dirB', 'fileB')) p = P(BASE, 'dirB', 'linkD', 'fileB') self._check_resolve_relative(p, P(BASE, 'dirB', 'fileB'))

@@ -1516,6 +1537,18 @@ class _BasePathTest(object): os.symlink(join('dirB'), os.path.join(d, 'linkY')) p = P(BASE, 'dirA', 'linkX', 'linkY', 'fileB') self._check_resolve_absolute(p, P(BASE, 'dirB', 'fileB'))

@with_symlinks def test_resolve_dot(self): @@ -1525,7 +1558,11 @@ class _BasePathTest(object): self.dirlink(os.path.join('0', '0'), join('1')) self.dirlink(os.path.join('1', '1'), join('2')) q = p / '2'

def test_with(self): p = self.cls(BASE) @@ -1972,10 +2009,10 @@ class PathTest(_BasePathTest, unittest.T class PosixPathTest(_BasePathTest, unittest.TestCase): cls = pathlib.PosixPath

def test_open_mode(self): old_mask = os.umask(0) @@ -2008,7 +2045,6 @@ class PosixPathTest(_BasePathTest, unitt @with_symlinks def test_resolve_loop(self):

@@ -2016,6 +2052,8 @@ class PosixPathTest(_BasePathTest, unitt self._check_symlink_loop(BASE, 'linkY') os.symlink('linkZ/../linkZ', join('linkZ')) self._check_symlink_loop(BASE, 'linkZ')

@@ -2023,6 +2061,8 @@ class PosixPathTest(_BasePathTest, unitt self._check_symlink_loop(BASE, 'linkV') os.symlink(join('linkW/../linkW'), join('linkW')) self._check_symlink_loop(BASE, 'linkW')

def test_glob(self): P = self.cls

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -23,6 +23,9 @@ Core and Builtins Library ------- +- Issue #19717: Makes Path.resolve() succeed on paths that do not exist.