bpo-43757: make pathlib use os.path.realpath() to resolve all symlinks in a path by barneygale · Pull Request #25264 · python/cpython (original) (raw)
Not declaring an opinion yet on the behaviour change, but I think it's probably okay. I'd be happier if the link cycle change was also tied to the strict argument. (My main concern is that virtually nobody will be testing for it, and it can become an issue based entirely on user's setup - nothing to do with the code that will fail.)
I can make the new symlink loop handling optional, but in order to use it from pathlib it would need to be an additional argument, as pathlib.Path.resolve()
always raises on broken symlinks regardless of the value of strict
. So I'd need to adjust this patch to add two arguments to realpath()
, which I'm happy to do if we feel it's the way forward.
I'd argue that the new behaviour is justified because the current behaviour seems entirely non-useful. I can't find another example of a realpath
function/executable that doesn't error out when it hits a symlink loop - even PHP's version seems to return false
in this case. I suspect the system misconfiguration in your example will result in an exception regardless of this change, as the result of realpath()
will be fed into something that will barf on the symlink loop. Better to fail earlier?