Skip to content

Conversation

@barneygale
Copy link
Contributor

@barneygalebarneygale commented May 26, 2024

For silly reasons, pathlib's generic implementation of walk() currently resides in glob._Globber. This commit moves it into pathlib._abc.PathBase.walk() where it really belongs, and makes pathlib.Path.walk() call though to os.walk() rather than using the generic impl.

Symlink handling is a little different between the two walk() implementations when followlinks=False. In pathlib it means never following symlinks, not even for distinguishing between files and directories. In os it means never walking into symlinks, including any symlinks created by the user between iterations. We smooth over these differences with a private sentinel - os._walk_symlinks_as_files - that enables the pathlib behaviour.

No change of behaviour.

For silly reasons, pathlib's generic implementation of `walk()` currently resides in `glob._Globber`. This commit moves it into `pathlib._abc.PathBase.walk()` where it really belongs, and makes `pathlib.Path.walk()` call though to `os.walk()`. Symlink handling is a little different between the two `walk()` implementations when `followlinks=False`. In `pathlib` it means never following symlinks, not even for distinguishing between files and directories. In `os` it means never *walking* into symlinks, including any symlinks created by the user between iterations. We smooth over these differences with a private sentinel - `os._walk_symlinks_as_files` - that enables the pathlib behaviour.
@barneygale
Copy link
ContributorAuthor

barneygale commented May 29, 2024

I'm intensely embarrassed by my decision to add a _Globber.walk() method to glob.py despite it having little to do with globbing, and so I'm going to merge this PR before anyone else notices my poor life choices.

@barneygalebarneygale added the needs backport to 3.13 bugs and security fixes label May 29, 2024
@barneygalebarneygale enabled auto-merge (squash) May 29, 2024 20:37
@barneygalebarneygale merged commit 7ff61f5 into python:mainMay 29, 2024
@miss-islington-app
Copy link

Thanks @barneygale for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 29, 2024
…ythonGH-119573) For silly reasons, pathlib's generic implementation of `walk()` currently resides in `glob._Globber`. This commit moves it into `pathlib._abc.PathBase.walk()` where it really belongs, and makes `pathlib.Path.walk()` call `os.walk()`. (cherry picked from commit 7ff61f5) Co-authored-by: Barney Gale <barney.gale@gmail.com>
@bedevere-app
Copy link

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

@bedevere-appbedevere-appbot removed the needs backport to 3.13 bugs and security fixes label May 29, 2024
barneygale added a commit that referenced this pull request May 29, 2024
…H-119573) (#119750) GH-119169: Implement `pathlib.Path.walk()` using `os.walk()` (GH-119573) For silly reasons, pathlib's generic implementation of `walk()` currently resides in `glob._Globber`. This commit moves it into `pathlib._abc.PathBase.walk()` where it really belongs, and makes `pathlib.Path.walk()` call `os.walk()`. (cherry picked from commit 7ff61f5) Co-authored-by: Barney Gale <barney.gale@gmail.com>
noahbkim pushed a commit to hudson-trading/cpython that referenced this pull request Jul 11, 2024
…ython#119573) For silly reasons, pathlib's generic implementation of `walk()` currently resides in `glob._Globber`. This commit moves it into `pathlib._abc.PathBase.walk()` where it really belongs, and makes `pathlib.Path.walk()` call `os.walk()`.
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
…ython#119573) For silly reasons, pathlib's generic implementation of `walk()` currently resides in `glob._Globber`. This commit moves it into `pathlib._abc.PathBase.walk()` where it really belongs, and makes `pathlib.Path.walk()` call `os.walk()`.
Sign up for freeto 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.

1 participant

@barneygale