diff --git a/Lib/posixpath.py b/Lib/posixpath.py index fccca4e066b76f..565ffd136c55ce 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -428,12 +428,11 @@ def _realpath(filename, strict=False, sep=sep, curdir=curdir, pardir=pardir, while rest: name = rest.pop() - if name is None: - # resolved symlink target - seen[rest.pop()] = path - continue if not name or name == curdir: # current dir + if name is None: + # resolved symlink target + seen[rest.pop()] = path continue if name == pardir: # parent dir diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-10-08-21-29-30.gh-issue-125159.jmi9FB.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-10-08-21-29-30.gh-issue-125159.jmi9FB.rst new file mode 100644 index 00000000000000..d316544cfc395b --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2024-10-08-21-29-30.gh-issue-125159.jmi9FB.rst @@ -0,0 +1 @@ +Speed up :func:`os.path.realpath` on Unix.