bpo-43757: Make pathlib use os.path.realpath() to resolve symlinks in a path (GH-25264)

Also adds a new "strict" argument to realpath() to avoid changing the default behaviour of pathlib while sharing the implementation.
This commit is contained in:
Barney Gale 2021-04-28 16:50:17 +01:00 committed by GitHub
parent 859577c249
commit baecfbd849
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 184 additions and 109 deletions

View file

@ -635,7 +635,7 @@ else:
tail = join(name, tail) if tail else name
return tail
def realpath(path):
def realpath(path, *, strict=False):
path = normpath(path)
if isinstance(path, bytes):
prefix = b'\\\\?\\'
@ -660,6 +660,8 @@ else:
path = _getfinalpathname(path)
initial_winerror = 0
except OSError as ex:
if strict:
raise
initial_winerror = ex.winerror
path = _getfinalpathname_nonstrict(path)
# The path returned by _getfinalpathname will always start with \\?\ -