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
gh-89727: Fix pathlib.Path.walk RecursionError on deep trees #100282
base: main
Are you sure you want to change the base?
gh-89727: Fix pathlib.Path.walk RecursionError on deep trees #100282
Conversation
|
Name | Link |
---|---|
2bfc47d | |
https://app.netlify.com/sites/python-cpython-preview/deploys/639c50140be628000884140d |
TODO:
Update: |
…f github.com:ovsyanka83/cpython into pythongh-89727/fix-pathlib.Path.walk-recursion-depth
/cc @barneygale |
Lib/test/test_pathlib.py
Outdated
path = pathlib.Path(base, *(['d']*50)) | ||
path.mkdir(parents=True) | ||
|
||
with infinite_recursion(40): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that it was merged in the os.walk
PR, maybe use test.support.set_recursion_limit
here? Although in practice the functionality is the same, the name infinite_recursion
is inappropriate to this use and may confuse the reader regarding the purpose of the test (this test has nothing to do with infinite recursion.)
with infinite_recursion(40): | |
with set_recursion_limit(40): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! That was my intention all along to also use set_recursion_limit
but I wanted to wait until it gets merged to prevent duplicate commits and possible merge conflicts that could arise if I did anything slightly differently.
@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. |
Use a stack to implement pathlib.Path.walk iteratively instead of recursively to avoid hitting recursion limits on deeply nested trees.