Skip to content
Closed
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
fix scandir comment
  • Loading branch information
jonburdo committed Jan 4, 2023
commit 839f31eb34e5ecc4ddf5cb0060487483fb788513
11 changes: 6 additions & 5 deletions Lib/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,12 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
sys.audit("os.walk", top, topdown, onerror, followlinks)

top = fspath(top)

# We may not have read permission for top, in which case we can't
# get a list of the files the directory contains.
# We suppress the exception here, rather than blow up for a
# minor reason when (say) a thousand readable directories are still
# left to visit.
try:
scandir_it = scandir(top)
except OSError as error:
Expand All @@ -357,11 +363,6 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
walk_dirs = []
use_entry = True

# We may not have read permission for top, in which case we can't
# get a list of the files the directory contains.
# We suppress the exception here, rather than blow up for a
# minor reason when (say) a thousand readable directories are still
# left to visit.
with scandir_it:
while True:
try:
Expand Down