Skip to content

Commit c5269d7

Browse files
committed
docs: be clearer that glob results are unordered
1 parent 7f371ed commit c5269d7

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

Doc/library/glob.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ ranges expressed with ``[]`` will be correctly matched. This is done by using
2525
the :func:`os.scandir` and :func:`fnmatch.fnmatch` functions in concert, and
2626
not by actually invoking a subshell.
2727

28+
.. note::
29+
The pathnames are returned in no particular order. If you need a specific
30+
order, sort the results.
31+
2832
Note that files beginning with a dot (``.``) can only be matched by
2933
patterns that also start with a dot,
3034
unlike :func:`fnmatch.fnmatch` or :func:`pathlib.Path.glob`.

Lib/glob.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ def glob(pathname, *, root_dir=None, dir_fd=None, recursive=False,
2222
dot are special cases that are not matched by '*' and '?'
2323
patterns by default.
2424
25+
The order of the returned list is undefined. Sort it if you need a
26+
particular order.
27+
2528
If `include_hidden` is true, the patterns '*', '?', '**' will match hidden
2629
directories.
2730
@@ -40,6 +43,9 @@ def iglob(pathname, *, root_dir=None, dir_fd=None, recursive=False,
4043
dot are special cases that are not matched by '*' and '?'
4144
patterns.
4245
46+
The order of the returned paths is undefined. Sort them if you need a
47+
particular order.
48+
4349
If recursive is true, the pattern '**' will match any files and
4450
zero or more directories and subdirectories.
4551
"""

0 commit comments

Comments
 (0)