diff options
author | Barney Gale <barney.gale@gmail.com> | 2024-12-05 21:39:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-05 21:39:43 (GMT) |
commit | 8b3cccf3f9508572d85b0044519f2bd5715dacad (patch) | |
tree | 9c5e6a23fa26ef59fa0db986ccf9bf4a1bd3a9a2 /Lib/pathlib | |
parent | f4f530804b9d8f089eba0f157ec2144c03b13651 (diff) | |
download | cpython-8b3cccf3f9508572d85b0044519f2bd5715dacad.zip cpython-8b3cccf3f9508572d85b0044519f2bd5715dacad.tar.gz cpython-8b3cccf3f9508572d85b0044519f2bd5715dacad.tar.bz2 |
GH-125413: Revert addition of `pathlib.Path.scandir()` method (#127377)
Remove documentation for `pathlib.Path.scandir()`, and rename the method to
`_scandir()`. In the private pathlib ABCs, make `iterdir()` abstract and
call it from `_scandir()`.
It's not worthwhile to add this method at the moment - see discussion:
https://discuss.python.org/t/ergonomics-of-new-pathlib-path-scandir/71721
Co-authored-by: Steve Dower <steve.dower@microsoft.com>
Diffstat (limited to 'Lib/pathlib')
-rw-r--r-- | Lib/pathlib/_abc.py | 15 | ||||
-rw-r--r-- | Lib/pathlib/_local.py | 4 |
2 files changed, 9 insertions, 10 deletions
diff --git a/Lib/pathlib/_abc.py b/Lib/pathlib/_abc.py index 2b314b6..86617ff 100644 --- a/Lib/pathlib/_abc.py +++ b/Lib/pathlib/_abc.py @@ -94,7 +94,7 @@ class PathGlobber(_GlobberBase): lexists = operator.methodcaller('exists', follow_symlinks=False) add_slash = operator.methodcaller('joinpath', '') - scandir = operator.methodcaller('scandir') + scandir = operator.methodcaller('_scandir') @staticmethod def concat_path(path, text): @@ -632,13 +632,14 @@ class PathBase(PurePathBase): with self.open(mode='w', encoding=encoding, errors=errors, newline=newline) as f: return f.write(data) - def scandir(self): - """Yield os.DirEntry objects of the directory contents. + def _scandir(self): + """Yield os.DirEntry-like objects of the directory contents. The children are yielded in arbitrary order, and the special entries '.' and '..' are not included. """ - raise UnsupportedOperation(self._unsupported_msg('scandir()')) + import contextlib + return contextlib.nullcontext(self.iterdir()) def iterdir(self): """Yield path objects of the directory contents. @@ -646,9 +647,7 @@ class PathBase(PurePathBase): The children are yielded in arbitrary order, and the special entries '.' and '..' are not included. """ - with self.scandir() as entries: - names = [entry.name for entry in entries] - return map(self.joinpath, names) + raise UnsupportedOperation(self._unsupported_msg('iterdir()')) def _glob_selector(self, parts, case_sensitive, recurse_symlinks): if case_sensitive is None: @@ -698,7 +697,7 @@ class PathBase(PurePathBase): if not top_down: paths.append((path, dirnames, filenames)) try: - with path.scandir() as entries: + with path._scandir() as entries: for entry in entries: name = entry.name try: diff --git a/Lib/pathlib/_local.py b/Lib/pathlib/_local.py index b5d9dc4..bb8a252 100644 --- a/Lib/pathlib/_local.py +++ b/Lib/pathlib/_local.py @@ -634,8 +634,8 @@ class Path(PathBase, PurePath): path_str = path_str[:-1] yield path_str - def scandir(self): - """Yield os.DirEntry objects of the directory contents. + def _scandir(self): + """Yield os.DirEntry-like objects of the directory contents. The children are yielded in arbitrary order, and the special entries '.' and '..' are not included. |