Skip to content

gh-126055: Add omitted command (in docs [os.walk]) for code to fulfill shutil.rmtree algorithm #126067

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 2 commits into from
Oct 30, 2024

Conversation

vwheeler63
Copy link
Contributor

@vwheeler63 vwheeler63 commented Oct 28, 2024

In ./Doc/library/os.rst, the section documenting os.walk() gives a code example at the bottom that says it is "a simple implementation of shutil.rmtree()". However it is incomplete. Reason: shutil.rmtree() also removes the passed directory whereas the code shown will not. This PR adds the last missing command to complete the algorithm and make the statement correct.

Resolves #126055


📚 Documentation preview 📚: https://cpython-previews--126067.org.readthedocs.build/

@ghost
Copy link

ghost commented Oct 28, 2024

All commit authors signed the Contributor License Agreement.
CLA signed

Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

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

Thanks for the clean PR!

This is one of the possible patches. Another possibility is to just mention that we are walking bottom-up but only mention that this is what shutil.rmtree needs to do.

The example is already dangerous as it is so I don't think it's an issue to also add the os.rmdir(top) in the example (I mean... you'd either end up with an empty directory or... no directory at all which, if you made a mistake, doesn't matter at that point).

cc @ncoghlan @barneygale as docs and pathlib experts (I don't have commit privileges so I cannot merge this PR).

@vwheeler63
Copy link
Contributor Author

Thanks for the clean PR!

I'm honored:

  1. to be talking with YOU (the maintainer of sphinx-doc!!), and
  2. to be able to contribute to these docs (and maybe more later).

It happens that before I saw that section in the documentation, I had been playing with os.walk() myself before I ran into shutil.rmtree() -- in fact, I was in the process of refactoring some Python code in the docs-build for https://github.com/lvgl/lvgl/ (which builds with a fairly elaborate Doxygen => Sphinx+breathe combination), and built a test with os.walk() indeed to do a clean-up step at the end of the docs build. And found that I needed to explicitly remove the top directory after the loop. I didn't even know yet that similar code was in the https://docs.python.org/3.12/library/os.html page, so when I read the section on os.walk(), it jumped out at me since I had just been doing almost exactly the same thing in a test environment.

That said -- HELLO! I'm honored to be in touch with you. :-)

@vwheeler63
Copy link
Contributor Author

vwheeler63 commented Oct 28, 2024

@picnixz FYI, I just recently helped to untangle the first half of the LVGL library documentation, and am now in a big proofreading sequence to make it more friendly (I don't mind calling it Queen's English) to native-English C programmers.

By the way, I just saw the "This branch is out-of-date with the base branch" message come up. Do I need to rebase it on top of master?

@picnixz
Copy link
Member

picnixz commented Oct 28, 2024

By the way, I just saw the "This branch is out-of-date with the base branch" message come up. Do I need to rebase it on top of master?

No need for that. We only rebase it if 1) there are conflicts that need to be fixed 2) to make the CI green if a fix has been pushed on main. (In general, docs PRs rarely need to be updated except for merge conflicts since they only trigger simple doc tests and not the entire test suite).

FYI, I just recently helped to untangle the first half of the

If you find any typos in Python documentation or if there are sentences that need to be improved, you're always welcome to make a PR out of it! or you can have a look at https://discuss.python.org/c/documentation/26 where the docs community discuss (maybe you can help them out there).

@vwheeler63
Copy link
Contributor Author

vwheeler63 commented Oct 28, 2024

No need for that.

Okay! I'm glad I asked. I had the impression that message indicating the merge was being blocked, but I am glad it isn't.

... you're always welcome to make a PR out of it!

I'm honored! Thank you!

I did find some real usability issues, but I believe it is really part of the design of the navigation-panel generation of the python-docs-theme. I see it has a "home" on GitHub as well!

Also: thank you for the link to the Python docs group! I'm checking it out now.

I haven't yet dived into how Sphinx themes work, but... I'm a 32-year veteran software developer (been working mostly in automotive firmware, close to the CPU [and supporting software] for the last 13 years), I'm a C master [+C#, VB.NET, optimization], heavily O-O trained (design & coding, by Bertrand Meyer himself [directly and indirectly]), and have been really enjoying learning Python lately. I'm also looking for paid work, in case you're aware of any opportunities that might be a good match for my skill set.

That said, with all that behind me, Sphinx themes should be a blast! 😄

Copy link
Contributor

@willingc willingc left a comment

Choose a reason for hiding this comment

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

Thanks @vwheeler63 for the PR. And congrats for the first commit!

Nice work @picnixz coaching on the PR and its review.

@willingc willingc added needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes labels Oct 30, 2024
@vwheeler63
Copy link
Contributor Author

Thanks @vwheeler63 for the PR. And congrats for the first commit!

I'm honored, Carol! **...and envious of your sphere of responsibility!** 😈 😃 👋

@willingc willingc merged commit 597d814 into python:main Oct 30, 2024
34 checks passed
@miss-islington-app
Copy link

Thanks @vwheeler63 for the PR, and @willingc for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 30, 2024
…fulfill `shutil.rmtree` algorithm (pythonGH-126067)

* pythongh-126055:  Add omitted command (in docs [os.walk]) for code to fulfill `shutil.rmtree` algorithm.

Resolves pythonGH-126055

* pythongh-126055:  Fix omitted code highlighting
(cherry picked from commit 597d814)

Co-authored-by: Victor Wheeler <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 30, 2024
…fulfill `shutil.rmtree` algorithm (pythonGH-126067)

* pythongh-126055:  Add omitted command (in docs [os.walk]) for code to fulfill `shutil.rmtree` algorithm.

Resolves pythonGH-126055

* pythongh-126055:  Fix omitted code highlighting
(cherry picked from commit 597d814)

Co-authored-by: Victor Wheeler <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Oct 30, 2024

GH-126199 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Oct 30, 2024
@bedevere-app
Copy link

bedevere-app bot commented Oct 30, 2024

GH-126200 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 only security fixes label Oct 30, 2024
@vwheeler63 vwheeler63 deleted the fix-issue-126055 branch October 30, 2024 19:34
@vwheeler63
Copy link
Contributor Author

Thanks @vwheeler63 for the PR, and @willingc for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13. 🐍🍒⛏🤖

I love the Monty Python references by the bot-apps.... 😃

willingc pushed a commit that referenced this pull request Oct 30, 2024
… fulfill `shutil.rmtree` algorithm (GH-126067) (GH-126200)

gh-126055:  Add omitted command (in docs [os.walk]) for code to fulfill `shutil.rmtree` algorithm (GH-126067)

* gh-126055:  Add omitted command (in docs [os.walk]) for code to fulfill `shutil.rmtree` algorithm.

Resolves GH-126055

* gh-126055:  Fix omitted code highlighting
(cherry picked from commit 597d814)

Co-authored-by: Victor Wheeler <[email protected]>
willingc pushed a commit that referenced this pull request Oct 30, 2024
… fulfill `shutil.rmtree` algorithm (GH-126067) (GH-126199)

gh-126055:  Add omitted command (in docs [os.walk]) for code to fulfill `shutil.rmtree` algorithm (GH-126067)

* gh-126055:  Add omitted command (in docs [os.walk]) for code to fulfill `shutil.rmtree` algorithm.

Resolves GH-126055

* gh-126055:  Fix omitted code highlighting
(cherry picked from commit 597d814)

Co-authored-by: Victor Wheeler <[email protected]>
picnixz pushed a commit to picnixz/cpython that referenced this pull request Dec 8, 2024
…fulfill `shutil.rmtree` algorithm (pythonGH-126067)

* pythongh-126055:  Add omitted command (in docs [os.walk]) for code to fulfill `shutil.rmtree` algorithm.

Resolves python#126055

* pythongh-126055:  Fix omitted code highlighting
ebonnal pushed a commit to ebonnal/cpython that referenced this pull request Jan 12, 2025
…fulfill `shutil.rmtree` algorithm (pythonGH-126067)

* pythongh-126055:  Add omitted command (in docs [os.walk]) for code to fulfill `shutil.rmtree` algorithm.

Resolves python#126055

* pythongh-126055:  Fix omitted code highlighting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

os.walk() example of an implementation of shutil.rmtree() is incomplete
3 participants