[issue43968] os.path.realpath() unexpected breaking change: resolves subst'd paths to real paths

Eryk Sun report at bugs.python.org
Fri Apr 30 14:00:21 EDT 2021


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

> E.g. if you specify env. var. PYTHON_NTREALPATH_OLD_BEHAVIOR=1, 
> it doesn't resolve symlinks and junctions.

I assumed you wanted to resolve symlinks but hadn't considered that substitute drives are implemented as object symlinks that target arbitrary paths, which can include other substitute/mapped drives and filesystem symlinks. They aren't handled as mount points, at least not during system path parsing.

If you don't need to resolve symlinks, just use os.path.abspath() in Windows and os.path.realpath() in POSIX. Don't worry about symlinks in the opened path in Windows. Unlike POSIX, the Windows API resolves a path like r"C:\example\symlink\..\dir" simply as r"C:\example\dir", before the kernel and filesystem ever see the path. There are reasons to need a real path in Windows, but this isn't one of them.

----------

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


More information about the Python-bugs-list mailing list