← 返回首页
gh-89727: Fix pathlib.Path.walk RecursionError on deep trees by zmievsa · Pull Request #100282 · python/cpython · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

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

Provide feedback

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

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

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

Merged
barneygale merged 20 commits into
python:mainfrom
zmievsa:gh-89727/fix-pathlib.Path.walk-recursion-depth
Mar 22, 2023
Merged

gh-89727: Fix pathlib.Path.walk RecursionError on deep trees#100282
barneygale merged 20 commits into
python:mainfrom
zmievsa:gh-89727/fix-pathlib.Path.walk-recursion-depth

Conversation

zmievsa commented Dec 15, 2022
edited
Loading

Copy link
Copy Markdown
Contributor

Use a stack to implement pathlib.Path.walk iteratively instead of recursively to avoid hitting recursion limits on deeply nested trees.

netlify Bot commented Dec 15, 2022
edited
Loading

Copy link
Copy Markdown

Deploy Preview for python-cpython-preview canceled.

Name Link
🔨 Latest commit 2bfc47d
🔍 Latest deploy log https://app.netlify.com/sites/python-cpython-preview/deploys/639c50140be628000884140d

zmievsa commented Dec 15, 2022
edited
Loading

Copy link
Copy Markdown
Contributor Author

TODO:

  • Add a news blip
  • Add a test that checks for deeply nested directories
  • Figure out a better name for is_result

Update:
All done!

zmievsa marked this pull request as ready for review December 16, 2022 10:32
zmievsa requested a review from brettcannon as a code owner December 16, 2022 10:32

Copy link
Copy Markdown
Member

/cc @barneygale

Comment thread Lib/pathlib.py Outdated Show resolved Hide resolved
Comment thread Lib/test/test_pathlib.py Outdated Show resolved Hide resolved

carljm left a comment

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

LGTM. I assume because of the initial underscore we don't have to worry about people who may have subclassed Path and overridden the _walk method (now to no effect.)

zmievsa commented Dec 20, 2022

Copy link
Copy Markdown
Contributor Author

@carljm remember that Path.walk has only been created in 3.12 which means that 99% of libraries/projects do not and cannot depend on it yet.

zmievsa commented Dec 24, 2022

Copy link
Copy Markdown
Contributor Author

@barneygale any estimates of when you will have time to take a look at it? No pressure or rush though.

Copy link
Copy Markdown
Contributor

I'll look at this within the next few days!

25 hidden items Load more…
Comment thread Lib/pathlib.py Outdated Show resolved Hide resolved
Co-authored-by: Barney Gale <barney.gale@gmail.com>

barneygale left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

Looks good to me!

zmievsa commented Jan 11, 2023

Copy link
Copy Markdown
Contributor Author

@AlexWaygood what would be the next steps for this PR? I am ready to continue improving it

Copy link
Copy Markdown
Member

Sorry @Ovsyanka83, I'll try to take a proper look soon!

Comment thread Lib/pathlib.py Outdated Show resolved Hide resolved
Comment thread Lib/test/test_pathlib.py Outdated Show resolved Hide resolved
Co-authored-by: Brett Cannon <brett@python.org>

barneygale commented Feb 1, 2023
edited
Loading

Copy link
Copy Markdown
Contributor

@AlexWaygood gentle nudge to review this when you have the time! Thanks :)

CuriousLearner left a comment

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

LGTM.

Thanks for your contribution.

Copy link
Copy Markdown
Contributor

Comment thread Lib/pathlib.py Outdated Show resolved Hide resolved
barneygale merged commit 713df2c into python:main Mar 22, 2023

zmievsa commented Mar 22, 2023

Copy link
Copy Markdown
Contributor Author

@barneygale thanks!

Wow. Have you received merge rights? Congrats! Did they make you a core developer or is that a special rule just for you and pathlib?

zmievsa deleted the gh-89727/fix-pathlib.Path.walk-recursion-depth branch March 22, 2023 18:20

Copy link
Copy Markdown
Member

We made him a core dev! https://discuss.python.org/t/vote-to-promote-barney-gale/24801

Copy link
Copy Markdown
Contributor

@Ovsyanka83 thanks for your patience and for working on this, it's a neat patch :). I'm hoping to build an iterative version of glob() atop!

Fidget-Spinner pushed a commit to Fidget-Spinner/cpython that referenced this pull request Mar 27, 2023
…ythonGH-100282) Use a stack to implement `pathlib.Path.walk()` iteratively instead of recursively to avoid hitting recursion limits on deeply nested trees. Co-authored-by: Barney Gale <barney.gale@gmail.com> Co-authored-by: Brett Cannon <brett@python.org>
warsaw pushed a commit to warsaw/cpython that referenced this pull request Apr 11, 2023
…ythonGH-100282) Use a stack to implement `pathlib.Path.walk()` iteratively instead of recursively to avoid hitting recursion limits on deeply nested trees. Co-authored-by: Barney Gale <barney.gale@gmail.com> Co-authored-by: Brett Cannon <brett@python.org>
barneygale added a commit to barneygale/cpython that referenced this pull request May 11, 2023
Use `Path.walk()` to implement the recursive wildcard `**`. This method uses an iterative (rather than recursive) walk - see pythonGH-100282.
barneygale added a commit that referenced this pull request May 15, 2023
Use `Path.walk()` to implement the recursive wildcard `**`. This method uses an iterative (rather than recursive) walk - see GH-100282.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants

Footer

© 2026 GitHub, Inc.