Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Slightly speed up handling of empty/dot parts
  • Loading branch information
barneygale committed Feb 1, 2024
commit b7587109db4d1c2e47e4b75901c01477a1427f94
9 changes: 4 additions & 5 deletions Lib/posixpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,17 +448,15 @@ def realpath(filename, *, strict=False):
querying = True
path = sep if filename.startswith(sep) else getcwd()
for part in reversed(filename.split(sep)):
stack.append((False, part))
if part and part != curdir:
stack.append((False, part))

while stack:
is_symlink, name = stack.pop()
if is_symlink:
# resolved symlink
seen[name] = path
continue
if not name or name == curdir:
# current dir
continue
if name == pardir:
# parent dir
newpath, name = split(path)
Expand Down Expand Up @@ -509,7 +507,8 @@ def realpath(filename, *, strict=False):
path = sep
stack.append((True, newpath))
for part in reversed(target.split(sep)):
stack.append((False, part))
if part and part != curdir:
stack.append((False, part))
return path


Expand Down