diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2013-12-28 18:49:04 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2013-12-28 18:49:04 (GMT) |
commit | 156b3610b883f3d14c1a3d115f00a7e5d2437132 (patch) | |
tree | 08a1fada997730f1bf6455d3bc5e1cbe73529fdb /Lib/pathlib.py | |
parent | 68816ef0583c2284f53126a198a011f7d1eff3a5 (diff) | |
download | cpython-156b3610b883f3d14c1a3d115f00a7e5d2437132.zip cpython-156b3610b883f3d14c1a3d115f00a7e5d2437132.tar.gz cpython-156b3610b883f3d14c1a3d115f00a7e5d2437132.tar.bz2 |
Issue #19918: Fix PurePath.relative_to() under Windows.
Diffstat (limited to 'Lib/pathlib.py')
-rw-r--r-- | Lib/pathlib.py | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py index 18facd9..b999ab2 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -780,27 +780,23 @@ class PurePath(object): parts = self._parts drv = self._drv root = self._root - if drv or root: - if root: - abs_parts = [drv, root] + parts[1:] - else: - abs_parts = [drv] + parts[1:] + if root: + abs_parts = [drv, root] + parts[1:] else: abs_parts = parts to_drv, to_root, to_parts = self._parse_args(other) - if to_drv or to_root: - if to_root: - to_abs_parts = [to_drv, to_root] + to_parts[1:] - else: - to_abs_parts = [to_drv] + to_parts[1:] + if to_root: + to_abs_parts = [to_drv, to_root] + to_parts[1:] else: to_abs_parts = to_parts n = len(to_abs_parts) - if n == 0 and (drv or root) or abs_parts[:n] != to_abs_parts: + cf = self._flavour.casefold_parts + if (root or drv) if n == 0 else cf(abs_parts[:n]) != cf(to_abs_parts): formatted = self._format_parsed_parts(to_drv, to_root, to_parts) raise ValueError("{!r} does not start with {!r}" .format(str(self), str(formatted))) - return self._from_parsed_parts('', '', abs_parts[n:]) + return self._from_parsed_parts('', root if n == 1 else '', + abs_parts[n:]) @property def parts(self): |