8000 gh-89727: Fix pathlib.Path.walk RecursionError on deep trees by zmievsa · Pull Request #100282 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-89727: Fix pathlib.Path.walk RecursionError on deep trees #100282

8000
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
Rename stack to paths
  • Loading branch information
zmievsa committed Mar 19, 2023
commit 9bc2500855546a1cb4b83bedb75b02da1668c3d9
10 changes: 5 additions & 5 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1216,10 +1216,10 @@ 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 = [self]
paths = [self]

while stack:
path = stack.pop()
while paths:
path = paths.pop()
if isinstance(path, tuple):
yield path
continue
Expand Down Expand Up @@ -1254,9 +1254,9 @@ def walk(self, top_down=True, on_error=None, follow_symlinks=False):
if top_down:
yield path, dirnames, filenames
else:
stack.append((path, dirnames, filenames))
paths.append((path, dirnames, filenames))

stack += [path._make_child_relpath(d) for d in reversed(dirnames)]
paths += [path._make_child_relpath(d) for d in reversed(dirnames)]


class PosixPath(Path, PurePosixPath):
Expand Down
0