[3.14] docs: be clearer that glob results are unordered (GH-140184) (#140339)
Some checks are pending
Tests / Docs (push) Blocked by required conditions
Tests / (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / Change detection (push) Waiting to run
Tests / Check if the ABI has changed (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / Android (aarch64) (push) Blocked by required conditions
Tests / Android (x86_64) (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Sanitizers (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run

(cherry picked from commit ed672f7a8a)

Co-authored-by: Ned Batchelder <ned@nedbatchelder.com>
This commit is contained in:
Miss Islington (bot) 2025-10-20 06:31:05 +02:00 committed by GitHub
parent 13e1642845
commit 2699643d71
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 8 deletions

View file

@ -18,23 +18,27 @@
single: - (minus); in glob-style wildcards single: - (minus); in glob-style wildcards
single: . (dot); in glob-style wildcards single: . (dot); in glob-style wildcards
The :mod:`glob` module finds all the pathnames matching a specified pattern The :mod:`!glob` module finds pathnames
according to the rules used by the Unix shell, although results are returned in using pattern matching rules similar to the Unix shell.
arbitrary order. No tilde expansion is done, but ``*``, ``?``, and character No tilde expansion is done, but ``*``, ``?``, and character
ranges expressed with ``[]`` will be correctly matched. This is done by using ranges expressed with ``[]`` will be correctly matched. This is done by using
the :func:`os.scandir` and :func:`fnmatch.fnmatch` functions in concert, and the :func:`os.scandir` and :func:`fnmatch.fnmatch` functions in concert, and
not by actually invoking a subshell. 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, patterns that also start with a dot,
unlike :func:`fnmatch.fnmatch` or :func:`pathlib.Path.glob`. unlike :func:`fnmatch.fnmatch` or :func:`pathlib.Path.glob`.
(For tilde and shell variable expansion, use :func:`os.path.expanduser` and For tilde and shell variable expansion, use :func:`os.path.expanduser` and
:func:`os.path.expandvars`.) :func:`os.path.expandvars`.
For a literal match, wrap the meta-characters in brackets. For a literal match, wrap the meta-characters in brackets.
For example, ``'[?]'`` matches the character ``'?'``. 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, \ .. 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` 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 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 *pathname* is relative, the result will contain paths relative to
*root_dir*. *root_dir*.

View 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 '?' dot are special cases that are not matched by '*' and '?'
patterns by default. 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 If `include_hidden` is true, the patterns '*', '?', '**' will match hidden
directories. 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 '?' dot are special cases that are not matched by '*' and '?'
patterns. 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 If recursive is true, the pattern '**' will match any files and
zero or more directories and subdirectories. zero or more directories and subdirectories.
""" """