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
Code review fixes
  • Loading branch information
zmievsa committed Jan 1, 2023
commit 5609e4ff73cc916cc1c3f3a6aada0f4afa84eae5
18 changes: 9 additions & 9 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1214,12 +1214,12 @@ def expanduser(self):
def walk(self, top_down=True, on_error=None, follow_symlinks=False):
"""Walk the directory tree from this directory, similar to os.walk()."""
sys.audit("pathlib.Path.walk", self, on_error, follow_symlinks)
stack = [(False, self)]
stack = [self]
Comment thread
barneygale marked this conversation as resolved.
Outdated

while stack:
must_yield, top = stack.pop()
if must_yield:
yield top
path = stack.pop()
if isinstance(path, tuple):
yield path
continue

# We may not have read permission for self, in which case we can't
Expand All @@ -1228,7 +1228,7 @@ def walk(self, top_down=True, on_error=None, follow_symlinks=False):
# minor reason when (say) a thousand readable directories are still
# left to visit. That logic is copied here.
try:
scandir_it = top._scandir()
scandir_it = path._scandir()
except OSError as error:
if on_error is not None:
on_error(error)
Expand All @@ -1250,13 +1250,13 @@ def walk(self, top_down=True, on_error=None, follow_symlinks=False):
filenames.append(entry.name)

if top_down:
yield top, dirnames, filenames
yield path, dirnames, filenames
else:
stack.append((True, (top, dirnames, filenames)))
stack.append((path, dirnames, filenames))

for dirname in reversed(dirnames):
Comment thread
barneygale marked this conversation as resolved.
Outdated
dirpath = top._make_child_relpath(dirname)
stack.append((False, dirpath))
dirpath = path._make_child_relpath(dirname)
stack.append(dirpath)


class PosixPath(Path, PurePosixPath):
Expand Down