[issue40368] os.path.realpath uppercases Windows drive letter on Python 3.8

Eryk Sun report at bugs.python.org
Thu Apr 23 16:10:43 EDT 2020


Eryk Sun <eryksun at gmail.com> added the comment:

> `os.path.abspath(".")` returned 
> `'c:\\Users\\Kagami\\Documents\\GitHub\\gecko-dev'`. 
> Should `ntpath.normpaoh` make the drive letter uppercase?

ntpath.abspath and ntpath.normpath should preserve the input case for all components of a path because they don't query the system for the real path. On the other hand, ntpath.realpath in 3.8+ opens the path and queries the final path from the system. 

With drive-relative paths, ntpath.abspath does upper-case the drive letter. That's due to the underlying GutFullPathNameW call on Windows (an API function that normalizes a path as a string-only operation). We should just leave that up to Windows instead of trying to impose consistency. The behavior could be documented, however, along with other Windows behaviors such as per-drive working directories with drive-relative paths, DOS devices (e.g. "C:/Temp/con.txt" -> r"\\.\con") and stripping of trailing dots and spaces (e.g. "C:/Temp/spam. . ." -> r"C:\Temp\spam"). These cases make ntpath.abspath(path) more complicated than just the documented equivalent of ntpath.normpath(ntpath.join(os.getcwd(), path))` on "most platforms" (i.e. most POSIX platforms -- not Windows).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40368>
_______________________________________


More information about the Python-bugs-list mailing list