GH-125413: Add pathlib.Path.scandir() method (#126060)

Add `pathlib.Path.scandir()` as a trivial wrapper of `os.scandir()`. This
will be used to implement several `PathBase` methods more efficiently,
including methods that provide `Path.copy()`.
This commit is contained in:
Barney Gale 2024-11-01 01:19:01 +00:00 committed by GitHub
parent d0abd0b826
commit 260843df1b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 114 additions and 11 deletions

View file

@ -615,6 +615,14 @@ class Path(PathBase, PurePath):
path_str = path_str[:-1]
yield path_str
def scandir(self):
"""Yield os.DirEntry objects of the directory contents.
The children are yielded in arbitrary order, and the
special entries '.' and '..' are not included.
"""
return os.scandir(self)
def iterdir(self):
"""Yield path objects of the directory contents.