]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] docs: be clearer that glob results are unordered (GH-140184) (#140340)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 20 Oct 2025 04:32:05 +0000 (06:32 +0200)
committerGitHub <noreply@github.com>
Mon, 20 Oct 2025 04:32:05 +0000 (07:32 +0300)
(cherry picked from commit ed672f7a8a3c843d8e6e6b673d5a7c1f752f208c)

Co-authored-by: Ned Batchelder <ned@nedbatchelder.com>
Doc/library/glob.rst
Lib/glob.py

index 684466d354aef83433960738736f8962acab50c6..7580c564494e3a1964f714ea3d1ac3b0d7ed8496 100644 (file)
    single: - (minus); in glob-style wildcards
    single: . (dot); in glob-style wildcards
 
-The :mod:`glob` module finds all the pathnames matching a specified pattern
-according to the rules used by the Unix shell, although results are returned in
-arbitrary order.  No tilde expansion is done, but ``*``, ``?``, and character
+The :mod:`!glob` module finds pathnames
+using pattern matching rules similar to the Unix shell.
+No tilde expansion is done, but ``*``, ``?``, and character
 ranges expressed with ``[]`` will be correctly matched.  This is done by using
 the :func:`os.scandir` and :func:`fnmatch.fnmatch` functions in concert, and
 not by actually invoking a subshell.
 
-Note that files beginning with a dot (``.``) can only be matched by
+.. note::
+   The pathnames are returned in no particular order.  If you need a specific
+   order, sort the results.
+
+Files beginning with a dot (``.``) can only be matched by
 patterns that also start with a dot,
 unlike :func:`fnmatch.fnmatch` or :func:`pathlib.Path.glob`.
-(For tilde and shell variable expansion, use :func:`os.path.expanduser` and
-:func:`os.path.expandvars`.)
+For tilde and shell variable expansion, use :func:`os.path.expanduser` and
+:func:`os.path.expandvars`.
 
 For a literal match, wrap the meta-characters in brackets.
 For example, ``'[?]'`` matches the character ``'?'``.
 
-The :mod:`glob` module defines the following functions:
+The :mod:`!glob` module defines the following functions:
 
 
 .. function:: glob(pathname, *, root_dir=None, dir_fd=None, recursive=False, \
@@ -51,7 +55,7 @@ The :mod:`glob` module defines the following functions:
 
    If *root_dir* is not ``None``, it should be a :term:`path-like object`
    specifying the root directory for searching.  It has the same effect on
-   :func:`glob` as changing the current directory before calling it.  If
+   :func:`!glob` as changing the current directory before calling it.  If
    *pathname* is relative, the result will contain paths relative to
    *root_dir*.
 
index c506e0e2157c512a6f0e88e59157816d888d5867..f45177fb70fea41bf8b048814528bd3d2aa7ca25 100644 (file)
@@ -22,6 +22,9 @@ def glob(pathname, *, root_dir=None, dir_fd=None, recursive=False,
     dot are special cases that are not matched by '*' and '?'
     patterns by default.
 
+    The order of the returned list is undefined. Sort it if you need a
+    particular order.
+
     If `include_hidden` is true, the patterns '*', '?', '**'  will match hidden
     directories.
 
@@ -40,6 +43,9 @@ def iglob(pathname, *, root_dir=None, dir_fd=None, recursive=False,
     dot are special cases that are not matched by '*' and '?'
     patterns.
 
+    The order of the returned paths is undefined. Sort them if you need a
+    particular order.
+
     If recursive is true, the pattern '**' will match any files and
     zero or more directories and subdirectories.
     """