Skip to content
Prev Previous commit
Next Next commit
Merge branch 'main' into os-walk-speedup
  • Loading branch information
barneygale committed May 30, 2024
commit 2d957a8474ff0979fe8056275d3f208c46732103
10 changes: 6 additions & 4 deletions Lib/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,14 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
for entry in entries:
is_dir = False
try:
if entry.is_dir():
is_dir = True
if followlinks is _walk_symlinks_as_files:
is_dir = entry.is_dir(follow_symlinks=False) and not entry.is_junction()
else:
is_dir = entry.is_dir()
if is_dir and not topdown and (followlinks or not entry.is_symlink()):
# Bottom-up: traverse into sub-directory, but exclude
# symlinks to directories if followlinks is False
if not topdown and (followlinks or not entry.is_symlink()):
stack.append(entry.path)
stack.append(entry.path)
except OSError:
# If is_dir() raises an OSError, consider the entry not to
# be a directory, same behaviour as os.path.isdir().
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.