-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
os.path.relpath()
needlessly calls abspath()
when given two paths with matching anchors
#99199
Comments
On Windows, >>> ntpath.relpath('spam/eggs. . .', 'spam/eggs/foo')
'..' If we want to retain the ".." result here, then trailing dots and spaces will have to be stripped from the final component of each path. Otherwise the result will be "..\..\eggs. . .". There are also cases with DOS device names that will change if |
Funnily enough |
I'd prefer for Normalizing DOS device names is problematic because it depends on the Windows version. There's still consistent behavior for bare device names, such as "con" -> "\\.\con", but not "./con"2 or "con.txt". Footnotes
|
Ack, this doesn't work due to differences in collapsing leading
|
Closing this issue as the handling of |
relpath()
unconditionally callsabspath()
to make both its arguments absolute before comparing them. This is necessary if the supplied arguments have different anchors, but it is not necessary when the paths' anchors match. We can save a call togetcwd()
/_getfinalpathname()
by skipping theabspath()
call in this case. This should improve performance a little.For example, neither of the following should require a call to
abspath()
internally:The text was updated successfully, but these errors were encountered: