Skip to content

Commit e52f5bc

Browse files
[3.8] bpo-40486: Specify what happens if directory content change diring iteration (GH-22025) (GH-22094)
(cherry picked from commit 306cfb3) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent 1470c91 commit e52f5bc

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

Doc/library/glob.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ For example, ``'[?]'`` matches the character ``'?'``.
4343
(like :file:`/usr/src/Python-1.5/Makefile`) or relative (like
4444
:file:`../../Tools/\*/\*.gif`), and can contain shell-style wildcards. Broken
4545
symlinks are included in the results (as in the shell). Whether or not the
46-
results are sorted depends on the file system.
46+
results are sorted depends on the file system. If a file that satisfies
47+
conditions is removed or added during the call of this function, whether
48+
a path name for that file be included is unspecified.
4749

4850
.. index::
4951
single: **; in glob-style wildcards

Doc/library/os.rst

+9-2
Original file line numberDiff line numberDiff line change
@@ -1828,6 +1828,8 @@ features:
18281828
Return a list containing the names of the entries in the directory given by
18291829
*path*. The list is in arbitrary order, and does not include the special
18301830
entries ``'.'`` and ``'..'`` even if they are present in the directory.
1831+
If a file is removed from or added to the directory during the call of
1832+
this function, whether a name for that file be included is unspecified.
18311833

18321834
*path* may be a :term:`path-like object`. If *path* is of type ``bytes``
18331835
(directly or indirectly through the :class:`PathLike` interface),
@@ -2233,7 +2235,9 @@ features:
22332235
Return an iterator of :class:`os.DirEntry` objects corresponding to the
22342236
entries in the directory given by *path*. The entries are yielded in
22352237
arbitrary order, and the special entries ``'.'`` and ``'..'`` are not
2236-
included.
2238+
included. If a file is removed from or added to the directory after
2239+
creating the iterator, whether an entry for that file be included is
2240+
unspecified.
22372241

22382242
Using :func:`scandir` instead of :func:`listdir` can significantly
22392243
increase the performance of code that also needs file type or file
@@ -2983,7 +2987,10 @@ features:
29832987
*filenames* is a list of the names of the non-directory files in *dirpath*.
29842988
Note that the names in the lists contain no path components. To get a full path
29852989
(which begins with *top*) to a file or directory in *dirpath*, do
2986-
``os.path.join(dirpath, name)``.
2990+
``os.path.join(dirpath, name)``. Whether or not the lists are sorted
2991+
depends on the file system. If a file is removed from or added to the
2992+
*dirpath* directory during generating the lists, whether a name for that
2993+
file be included is unspecified.
29872994

29882995
If optional argument *topdown* is ``True`` or not specified, the triple for a
29892996
directory is generated before the triples for any of its subdirectories

Doc/library/pathlib.rst

+5
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,11 @@ call fails (for example because the path doesn't exist).
849849
PosixPath('docs/_static')
850850
PosixPath('docs/Makefile')
851851

852+
The children are yielded in arbitrary order, and the special entries
853+
``'.'`` and ``'..'`` are not included. If a file is removed from or added
854+
to the directory after creating the iterator, whether an path object for
855+
that file be included is unspecified.
856+
852857
.. method:: Path.lchmod(mode)
853858

854859
Like :meth:`Path.chmod` but, if the path points to a symbolic link, the

0 commit comments

Comments
 (0)