Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

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
Show file tree
Hide file tree
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
Apply suggestions from code review
Co-authored-by: Brett Cannon <brett@python.org>
  • Loading branch information
Ovsyanka83 and brettcannon authored Jan 21, 2023
commit 49d423711d8d5dff4cede4e70be167056bce7727
8 changes: 4 additions & 4 deletions 8 Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1225,10 +1225,10 @@ def walk(self, top_down=True, on_error=None, follow_symlinks=False):
continue

# We may not have read permission for self, in which case we can't
# get a list of the files the directory contains. os.walk
# always suppressed the exception then, rather than blow up for a
# minor reason when (say) a thousand readable directories are still
# left to visit. That logic is copied here.
# get a list of the files the directory contains. os.walk()
# always suppressed the exception in that instance, rather than
# blow up for a minor reason when (say) a thousand readable
# directories are still left to visit. That logic is copied here.
try:
scandir_it = path._scandir()
except OSError as error:
Expand Down
7 changes: 5 additions & 2 deletions 7 Lib/test/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2771,11 +2771,14 @@ def test_walk_many_open_files(self):
path = path / 'd'

def test_walk_above_recursion_limit(self):
recursion_limit = 40
# directory_depth > recursion_limit
directory_depth = recursion_limit + 10
base = pathlib.Path(os_helper.TESTFN, 'deep')
path = pathlib.Path(base, *(['d']*50))
path = pathlib.Path(base, *(['d'] * directory_depth))
path.mkdir(parents=True)

with set_recursion_limit(40):
with set_recursion_limit(recursion_limit):
list(base.walk())
list(base.walk(top_down=False))

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.