Skip to content
Prev Previous commit
Next Next commit
Undo trailing slash optimisation (moved to another PR)
  • Loading branch information
barneygale committed Jul 6, 2024
commit efd31e2ef5ce2c8d5132d165bef861b8dca6ae90
18 changes: 8 additions & 10 deletions Lib/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,16 +410,14 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
# Yield before sub-directory traversal if going top down
yield top, dirs, nondirs
# Traverse into sub-directories
if dirs:
prefix = join(top, top[:0])
for dirname in reversed(dirs):
new_path = prefix + dirname
# bpo-23605: os.path.islink() is used instead of caching
# entry.is_symlink() result during the loop on os.scandir() because
# the caller can replace the directory entry during the "yield"
# above.
if followlinks or not islink(new_path):
stack.append(new_path)
for dirname in reversed(dirs):
new_path = join(top, dirname)
# bpo-23605: os.path.islink() is used instead of caching
# entry.is_symlink() result during the loop on os.scandir() because
# the caller can replace the directory entry during the "yield"
# above.
if followlinks or not islink(new_path):
stack.append(new_path)

__all__.append("walk")

Expand Down