[New-bugs-announce] [issue43968] os.path.realpath() unexpected breaking change: resolves subst'd paths to real paths
report at bugs.python.org
Wed Apr 28 12:26:16 EDT 2021
New submission from sfmc <Sergey_Filimonov at mentor.com>:
For example if I mount directory
returns the real directory.
Use following commands in Windows to reproduce the issue:
subst Z: C:\example\dir
python.exe -c "import os; print(os.path.realpath('Z:\\'))"
Python 3.8 outputs:
Python 3.7 outputs:
This is unexpected behavior change and it breaks our scripts in many places, because we use mounts in Windows ("subst" command) and Linux ("mount" command).
We had to add our own implementation for realpath to our scripts, but it also affects other tools, such as Python debugger (breakpoints stopped working) and IDEs (such as PyCharm).
It can be argued whether the behavior to resolve mounts is good.
But this change breaks the ability to work with Python scripts in mounts.
I hope it can be fixed in Python 3.8.10.
I propose to fix it in Python 3.8.10 by adding to function
a new parameter (named for example "resolve_mounts"), like that:
os.path.realpath(path, *, resolve_mounts=False)
And if resolve_mounts==False, then the function should not resolve mounts in Windows ("subst" command) and Linux ("mount" command).
Let me know if you wish to get a Pull Request with the proposed fix. I can try to implement it.
components: Library (Lib)
title: os.path.realpath() unexpected breaking change: resolves subst'd paths to real paths
versions: Python 3.8
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce