Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Merge branch 'main' into pathlib-fwalk2
  • Loading branch information
barneygale committed May 8, 2023
commit e074ffe4769ba4d752d94210488613a0eaf18009
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,11 @@ inspect
pathlib
-------

* Add support for subclassing :class:`pathlib.PurePath` and
:class:`~pathlib.Path`, plus their Posix- and Windows-specific variants.
Subclasses may override the :meth:`~pathlib.PurePath.with_segments` method
to pass information between path instances.

* Add :meth:`~pathlib.Path.walk` and :meth:`~pathlib.Path.fwalk`
for walking the directory trees and generating all file or directory names
within them, similar to :func:`os.walk` and :func:`~os.fwalk`.
Expand Down
19 changes: 19 additions & 0 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,24 @@ def _select_from(self, parent_path, scandir):
return


class _DoubleRecursiveWildcardSelector(_RecursiveWildcardSelector):
"""
Like _RecursiveWildcardSelector, but also de-duplicates results from
successive selectors. This is necessary if the pattern contains
multiple non-adjacent '**' segments.
"""

def _select_from(self, parent_path, scandir):
yielded = set()
try:
for p in super()._select_from(parent_path, scandir):
if p not in yielded:
yield p
yielded.add(p)
finally:
yielded.clear()


class _WalkAction:
WALK = object()
YIELD = object()
Expand Down Expand Up @@ -251,6 +269,7 @@ def _walk(top_down, on_error, follow_symlinks, use_fd, actions):
on_error(error)



#
# Public API
#
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.