Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
Closed
Description
On Windows, the pathC: means "the current directory on the C: drive".
But pathlib'srelative_to() treats it as the immediate parent ofC:\. This makes sense lexographically, but it's inconsistent with everything else:
C:\Users\Barney>python>>>importntpath,pathlib>>>ntpath.relpath('C:/Windows','C:/Users/Barney')'..\\..\\Windows'>>>ntpath.relpath('C:/Windows','.')'..\\..\\Windows'>>>ntpath.relpath('C:/Windows','C:')'..\\..\\Windows'>>>pathlib.Path('C:/Windows').relative_to('C:/Users/Barney',walk_up=True)WindowsPath('../../Windows')>>>pathlib.Path('C:/Windows').relative_to('.',walk_up=True)ValueError:Onepathisrelativeandtheotherisabsolute.>>>pathlib.Path('C:/Windows').relative_to('C:')WindowsPath('/Windows')# should be ValueError, as we're mixing absolute + relative paths
This prevents us from usingrelpath() from pathlib, and renders the two implementations incompatible. Booo! Also prevents us from simplifyingis_relative_to() down toother == self or other in self.parents
Special cases aren't special enough to break the rules. Let's make these compatible!
Previous discussion:#84538