New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disagreement between PureWindowsPath.relative_to() and ntpath.relpath() with rootless drives
#99029
Comments
…e_to('C:')`
`relative_to()` now treats naked drive paths as relative. This brings its
behaviour in line with other parts of pathlib, and with `ntpath.relpath()`,
and so allows us to factor out the pathlib-specific implementation.
|
Pathlib uses a pure implementation that doesn't rely on global state, such as the current working directory or current operating system (the implementation is in If anything, we should make Provided |
Indeed. This seems to be the only case where I've logged #99199 to cover |
|
I found another incompatibility between This bug is still valid, but we can't fix it by using |
…C:')` (GH-99031) `relative_to()` now treats naked drive paths as relative. This brings its behaviour in line with other parts of pathlib, and with `ntpath.relpath()`, and so allows us to factor out the pathlib-specific implementation.


barneygale commentedNov 2, 2022
•
edited
On Windows, the path
C:means "the current directory on the C: drive".But pathlib's
relative_to()treats it as the immediate parent ofC:\. This makes sense lexographically, but it's inconsistent with everything else:This prevents us from using
relpath()from pathlib, and renders the two implementations incompatible. Booo! Also prevents us from simplifyingis_relative_to()down toother == self or other in self.parentsSpecial cases aren't special enough to break the rules. Let's make these compatible!
Previous discussion: #84538
PureWindowsPath('C:\<blah>').relative_to('C:')#99031The text was updated successfully, but these errors were encountered: