Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ac622b7
Add Path.walk and Path.walk_bottom_up methods
zmievsa May 8, 2022
14f031a
Fix errors in Path.walk docstrings and add caching of entries
zmievsa May 9, 2022
b203517
Merge branch 'main' into bpo-46227/add-pathlib.Path.walk-method
Ovsyanka83 May 9, 2022
3ad60a9
Refactor symlink handling
zmievsa May 9, 2022
889d7fe
Merge branch 'bpo-46227/add-pathlib.Path.walk-method' of github.com:O…
zmievsa May 9, 2022
2f98823
Add Path.walk docs and unite Path.walk interfaces
zmievsa May 10, 2022
513030a
Remove Path.walk_bottom_up definition
zmievsa May 10, 2022
5fdd72e
📜🤖 Added by blurb_it.
blurb-it[bot] May 10, 2022
452f24e
Add Path.walk tests
zmievsa May 10, 2022
3702a12
Make Path.walk variable naming consistent
zmievsa May 10, 2022
fabc925
Remove redundant FIXME
zmievsa May 10, 2022
b387b54
Minor Path.walk docs and tests fixes
zmievsa May 10, 2022
097fbbf
Merge branch 'main' into bpo-46227/add-pathlib.Path.walk-method
Jun 27, 2022
76fadfc
Update Doc/library/pathlib.rst
Ovsyanka83 Jun 30, 2022
0c19871
Update Doc/library/pathlib.rst
Ovsyanka83 Jun 30, 2022
50b4a2b
Update Doc/library/pathlib.rst
Ovsyanka83 Jun 30, 2022
cade3e9
Update Doc/library/pathlib.rst
Ovsyanka83 Jun 30, 2022
b32627c
Update Doc/library/pathlib.rst
Ovsyanka83 Jun 30, 2022
d1a0833
Update Doc/library/pathlib.rst
Ovsyanka83 Jun 30, 2022
e367f1f
Update Doc/library/pathlib.rst
Ovsyanka83 Jun 30, 2022
bf8b0eb
Fix 'no blank lines' error
zmievsa Jun 30, 2022
d8667c7
Apply suggestions from code review
Ovsyanka83 Jul 3, 2022
4509797
More code review fixes for Path.walk
zmievsa Jul 3, 2022
20a73ed
Merge branch 'main' into bpo-46227/add-pathlib.Path.walk-method
Ovsyanka83 Jul 3, 2022
e61d57b
Merge branch 'main' into bpo-46227/add-pathlib.Path.walk-method
brettcannon Jul 8, 2022
15d96b9
Apply suggestions from code review
Ovsyanka83 Jul 9, 2022
92e1a7a
Apply suggestions from code review
Ovsyanka83 Jul 9, 2022
c509da3
Merge branch 'main' into bpo-46227/add-pathlib.Path.walk-method
Ovsyanka83 Jul 9, 2022
cfa730d
Code review fixes
zmievsa Jul 10, 2022
7aec96d
Clarify pathlib.Path.walk() error handling
zmievsa Jul 10, 2022
38fe1e5
Apply suggestions from code review
Ovsyanka83 Jul 10, 2022
eef3ba3
Code review fixes
zmievsa Jul 10, 2022
4dfdcd7
Merge branch 'bpo-46227/add-pathlib.Path.walk-method' of github.com:O…
zmievsa Jul 10, 2022
8fe3b62
Apply suggestions from code review
Ovsyanka83 Jul 12, 2022
e8ea6ba
Code review fixes
zmievsa Jul 12, 2022
79cf8fd
Remove backticks around True and False
zmievsa Jul 13, 2022
bed850e
Apply suggestions from code review
Ovsyanka83 Jul 17, 2022
203ec3d
Apply suggestions from code review
zmievsa Jul 17, 2022
eef6054
Apply suggestions from code review
brettcannon Jul 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Code review fixes
  • Loading branch information
zmievsa committed Jul 12, 2022
commit e8ea6ba0a9b2c7d7ba05b68a75771892aa11aea3
8 changes: 4 additions & 4 deletions Doc/library/pathlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -963,15 +963,15 @@ call fails (for example because the path doesn't exist).
``dirpath / name``. Whether or not the lists are sorted is file
system-dependent.

If optional argument *top_down* is ``True`` or not specified, the triple for a
If optional argument *top_down* is true or not specified, the triple for a
Comment thread
zmievsa marked this conversation as resolved.
Outdated
directory is generated before the triples for any of its subdirectories
(directories are walked top-down). If *top_down* is ``False``, the triple
for a directory is generated after the triples for all of its subdirectories
(directories are walked bottom-up). No matter the value of *top_down*, the
list of subdirectories is retrieved before the tuples for the directory and
Comment thread
zmievsa marked this conversation as resolved.
Outdated
its subdirectories are walked.

When *top_down* is ``True``, the caller can modify the *dirnames* list in-place
When *top_down* is true, the caller can modify the *dirnames* list in-place
(For example, using :keyword:`del` or slice assignment), and :meth:`Path.walk`
Comment thread
zmievsa marked this conversation as resolved.
Outdated
will only recurse into the subdirectories whose names remain in *dirnames*;
this can be used to prune the search, or to impose a specific order of visiting,
Expand All @@ -988,13 +988,13 @@ call fails (for example because the path doesn't exist).
filename is available as the ``filename`` attribute of the exception object.

By default, :meth:`Path.walk` does not follow symbolic links, and instead adds them
to the *filenames* list. Set *follow_symlinks* to ``True`` to resolve symlinks
to the *filenames* list. Set *follow_symlinks* to true to resolve symlinks
and place them in *dirnames* and *filenames* as appropriate for their targets, and
consequently visit directories pointed to by symlinks (where supported).

.. note::

Be aware that setting *follow_symlinks* to ``True`` can lead to infinite
Be aware that setting *follow_symlinks* to true can lead to infinite
recursion if a link points to a parent directory of itself. :meth:`Path.walk`
does not keep track of the directories it has already visited.

Expand Down
24 changes: 9 additions & 15 deletions Lib/test/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2489,14 +2489,8 @@ class WalkTests(unittest.TestCase):
testing a bit more complex cases than Path's setup.
"""

# Wrapper to hide minor differences between different implementations
# of Path.walk (for example, Path.fwalk)
def walk(self, top, **kwargs):
return top.walk(**kwargs)

def setUp(self):
P = pathlib.Path
Comment thread
zmievsa marked this conversation as resolved.
Outdated
join = os.path.join
self.addCleanup(os_helper.rmtree, os_helper.TESTFN)

# Build:
Expand Down Expand Up @@ -2569,7 +2563,7 @@ def setUp(self):
def test_walk_topdown(self):
# Walk top-down.
Comment thread
zmievsa marked this conversation as resolved.
Outdated
P = pathlib.Path
all = list(self.walk(self.walk_path))
all = list(self.walk_path.walk())

self.assertEqual(len(all), 4)
# We can't know which order SUB1 and SUB2 will appear in.
Expand All @@ -2589,7 +2583,7 @@ def test_walk_prune(self, walk_path=None):
walk_path = self.walk_path
# Prune the search.
all = []
for root, dirs, files in self.walk(walk_path):
for root, dirs, files in walk_path.walk():
all.append((root, dirs, files))
# Don't descend into SUB1.
Comment thread
zmievsa marked this conversation as resolved.
Outdated
if 'SUB1' in dirs:
Expand All @@ -2608,7 +2602,7 @@ def test_file_like_path(self):

def test_walk_bottom_up(self):
# Walk bottom-up.
Comment thread
zmievsa marked this conversation as resolved.
Outdated
all = list(self.walk(self.walk_path, top_down=False))
all = list(self.walk_path.walk( top_down=False))

self.assertEqual(len(all), 4, all)
# We can't know which order SUB1 and SUB2 will appear in.
Expand All @@ -2630,7 +2624,7 @@ def test_walk_bottom_up(self):
@os_helper.skip_unless_symlink
def test_walk_follow_symlinks(self):
# Walk, following symlinks.
Comment thread
zmievsa marked this conversation as resolved.
Outdated
walk_it = self.walk(self.walk_path, follow_symlinks=True)
walk_it = self.walk_path.walk(follow_symlinks=True)
for root, dirs, files in walk_it:
if root == self.link_path:
self.assertEqual(dirs, [])
Expand All @@ -2643,13 +2637,13 @@ def test_walk_symlink_location(self):
""" Tests whether symlinks end up in filenames or dirnames depending
on the `follow_symlinks` argument
"""
walk_it = self.walk(self.walk_path, follow_symlinks=False)
walk_it = self.walk_path.walk(follow_symlinks=False)
for root, dirs, files in walk_it:
if root == self.sub2_path:
self.assertIn("link", files)
break
Comment thread
zmievsa marked this conversation as resolved.

walk_it = self.walk(self.walk_path, follow_symlinks=True)
walk_it = self.walk_path.walk(follow_symlinks=True)
for root, dirs, files in walk_it:
if root == self.sub2_path:
self.assertIn("link", dirs)
Expand All @@ -2658,7 +2652,7 @@ def test_walk_symlink_location(self):
def test_walk_bad_dir(self):
# Walk top-down.
Comment thread
zmievsa marked this conversation as resolved.
Outdated
errors = []
walk_it = self.walk(self.walk_path, on_error=errors.append)
walk_it = self.walk_path.walk(on_error=errors.append)
root, dirs, files = next(walk_it)
self.assertEqual(errors, [])
dir1 = 'SUB1'
Expand All @@ -2683,14 +2677,14 @@ def test_walk_many_open_files(self):
p = P(base, *(['d']*depth))
p.mkdir(parents=True)

iters = [self.walk(base, top_down=False) for _ in range(100)]
iters = [base.walk(top_down=False) for _ in range(100)]
for i in range(depth + 1):
expected = (p, ['d'] if i else [], [])
Comment thread
brettcannon marked this conversation as resolved.
Outdated
for it in iters:
self.assertEqual(next(it), expected)
p = p.parent
Comment thread
brettcannon marked this conversation as resolved.
Outdated

iters = [self.walk(base, top_down=True) for _ in range(100)]
iters = [base.walk(top_down=True) for _ in range(100)]
p = base
Comment thread
brettcannon marked this conversation as resolved.
Outdated
for i in range(depth + 1):
expected = (p, ['d'] if i < depth else [], [])
Comment thread
brettcannon marked this conversation as resolved.
Outdated
Expand Down