gh-81790: support "UNC" device paths in `ntpath.splitdrive()` by barneygale · Pull Request #91882 · python/cpython
As was discussed in previous comments, this PR changes the behavior of ntpath.splitdrive() to restrict support for drives in extended paths to just drive-letter and GUID volume names and the "UNC" device. OTOH, "\\.\" paths will continue to support any device name as a drive.
For example, splitdrive() will no longer support any of the following builtin device names (alternate names for "C:" in this case) as a drive in an extended path:
>>> os.path.realpath('//?/BootPartition/')
'\\\\?\\C:\\'
>>> os.path.realpath('//?/Harddisk0Partition2/')
'\\\\?\\C:\\'
>>> os.path.realpath('//?/HarddiskVolume2/')
'\\\\?\\C:\\'
The existing implementation handles these as absolute paths, i.e. paths that have both a drive and a root (per the definition used by both pathlib and the C++ filesystem library):
>>> os.path.splitdrive('//?/BootPartition/')
('//?/BootPartition', '/')
>>> os.path.splitdrive('//?/Harddisk0Partition2/')
('//?/Harddisk0Partition2', '/')
>>> os.path.splitdrive('//?/HarddiskVolume2/')
('//?/HarddiskVolume2', '/')
The new restricted behavior will affect the results of ismount(), join(), split(), relpath(), and commonpath().