--- pathlib.py 2020-04-22 01:25:20.763546402 +0200 +++ pathlib_new.py 2020-04-22 01:34:10.285543587 +0200 @@ -892,14 +892,20 @@ to_abs_parts = [to_drv, to_root] + to_parts[1:] else: to_abs_parts = to_parts - n = len(to_abs_parts) + cf = self._flavour.casefold_parts - if (root or drv) if n == 0 else cf(abs_parts[:n]) != cf(to_abs_parts): + n = 0 + for p1, p2 in zip(cf(abs_parts), cf(to_abs_parts)): + if p1 != p2: break + n += 1 + + if n == 0: formatted = self._format_parsed_parts(to_drv, to_root, to_parts) - raise ValueError("{!r} does not start with {!r}" - .format(str(self), str(formatted))) + raise ValueError("{!r} doesn't have any common parents with {!r}" + .format(str(self), str(formatted))) return self._from_parsed_parts('', root if n == 1 else '', - abs_parts[n:]) + (len(to_abs_parts)-n)*['..'] + + abs_parts[n:]) @property def parts(self):