mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
[3.13] GH-119169: Implement pathlib.Path.walk()
using os.walk()
(GH-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 7ff61f51b6
)
Co-authored-by: Barney Gale <barney.gale@gmail.com>
This commit is contained in:
parent
061abf8e4c
commit
a7aa7c41eb
3 changed files with 34 additions and 39 deletions
|
@ -623,7 +623,9 @@ class Path(PathBase, PurePath):
|
|||
"""Walk the directory tree from this directory, similar to os.walk()."""
|
||||
sys.audit("pathlib.Path.walk", self, on_error, follow_symlinks)
|
||||
root_dir = str(self)
|
||||
results = self._globber.walk(root_dir, top_down, on_error, follow_symlinks)
|
||||
if not follow_symlinks:
|
||||
follow_symlinks = os._walk_symlinks_as_files
|
||||
results = os.walk(root_dir, top_down, on_error, follow_symlinks)
|
||||
for path_str, dirnames, filenames in results:
|
||||
if root_dir == '.':
|
||||
path_str = path_str[2:]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue