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
clean up os.walk comments
  • Loading branch information
jonburdo committed Dec 18, 2022
commit 73138a6363e5b8276e10d4639e66788bcd7323f4
18 changes: 9 additions & 9 deletions Lib/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def walk(top, topdown=True, onerror=None, followlinks=False):

# We may not have read permission for top, in which case we can't
# get a list of the files the directory contains.
# We suppressed the exception here, rather than blow up for a
# 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:
Expand All @@ -381,8 +381,8 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
try:
is_dir = entry.is_dir()
except OSError:
# If is_dir() raises an OSError, consider that the entry is not
# a directory, same behaviour as os.path.isdir().
# If is_dir() raises an OSError, consider the entry not to
# be a directory, same behaviour as os.path.isdir().
is_dir = False

if is_dir:
Expand All @@ -391,17 +391,17 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
nondirs.append(entry.name)

if not topdown and is_dir:
# Bottom-up: traverse into sub-directory, but exclude symlinks to
# directories if followlinks is False
# Bottom-up: traverse into sub-directory, but exclude
# symlinks to directories if followlinks is False
if followlinks:
walk_into = True
else:
try:
is_symlink = entry.is_symlink()
except OSError:
# If is_symlink() raises an OSError, consider that the
# entry is not a symbolic link, same behaviour than
# os.path.islink().
# If is_symlink() raises an OSError, consider the
# entry not to be a symbolic link, same behaviour
# as os.path.islink().
is_symlink = False
walk_into = not is_symlink

Expand All @@ -410,8 +410,8 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
if cont:
continue

# Yield before sub-directory traversal if going top down
if topdown:
# Yield before sub-directory traversal if going top down
yield top, dirs, nondirs
# Traverse into sub-directories
islink, join = path.islink, path.join
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're caching these functions in locals, might as well do it outside the main while loop to micro-optimize a bit more.

Expand Down