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

Skip to content
Prev Previous commit
Next Next commit
Simplify code slightly
  • Loading branch information
barneygale committed May 30, 2024
commit 91b5a78584c1701af18938870c7fb4b33cd5ba4c
16 changes: 8 additions & 8 deletions Lib/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,21 +510,21 @@ def _fwalk(stack, isbytes, topdown, onerror, follow_symlinks):
name = entry.name
if isbytes:
name = fsencode(name)
is_dir = False

try:
is_dir = entry.is_dir()
if is_dir and not topdown:
# Bottom-up: traverse into sub-directory.
stack.append(
(_fwalk_walk, (
False, topfd, topprefix + name, name,
None if follow_symlinks else entry)))
except OSError:
# If is_dir() raises an OSError, consider the entry not to
# be a directory, same behaviour as os.path.isdir().
pass
is_dir = False

if is_dir:
if not topdown:
# Bottom-up: traverse into sub-directory.
stack.append(
(_fwalk_walk, (
False, topfd, topprefix + name, name,
None if follow_symlinks else entry)))
dirs.append(name)
else:
nondirs.append(name)
Expand Down