Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upbpo-38671: Make sure to return an absolute path in pathlib._WindowsFlavour.resolve() #17716
Conversation
87e0e37
to
78953ba
This guarentees we are returning an absolute path when the input `path` is relative. Nothing would change if `path` is already absolute.
78953ba
to
34c68f7
if previous_s == s: | ||
return path | ||
return os.path.join(s or os.getcwd(), *reversed(tail_parts)) |
This comment has been minimized.
This comment has been minimized.
eryksun
Dec 28, 2019
Contributor
At the beginning, I'd rather set s = path = os.path.abspath(path)
. Note that _getfinalpathname
calls CreateFileW
, which internally calls GetFullPathNameW
on all paths except for ones that begin with exactly "\\?\" (backslash only). This means that ".." components in normalized paths are resolved naively, so it's fine to do the same via abspath
. Calling abspath
at the start also lets us resolve special DOS-device paths such as "C:\Temp\nul.txt" -> "\\.\nul".
This comment has been minimized.
This comment has been minimized.
uranusjr
Dec 28, 2019
Author
Contributor
By “at the start” do you mean line 205? One advantage of _getfinalpathname
over abspath
is that it canonicalize the case (e.g. python.EXE
-> python.exe
), which abspath
can’t do. I think we need to keep that.
This comment has been minimized.
This comment has been minimized.
eryksun
Dec 28, 2019
Contributor
I meant line 194, i.e. replace s = str(path)
with s = path = os.path.abspath(path)
. I wasn't proposing to replace _getfinalpathname
. It is irreplaceable in this function.
uranusjr commentedDec 27, 2019
•
edited by bedevere-bot
https://bugs.python.org/issue38671