Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Doc/library/glob.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
--------------

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
according to the rules used by the Unix shell, and results are returned in
sorted order. 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 unlike :func:`fnmatch.fnmatch`,
Expand Down
2 changes: 1 addition & 1 deletion Lib/glob.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def glob(pathname, *, recursive=False):
If recursive is true, the pattern '**' will match any files and
zero or more directories and subdirectories.
"""
return list(iglob(pathname, recursive=recursive))
return sorted(iglob(pathname, recursive=recursive))

def iglob(pathname, *, recursive=False):
"""Return an iterator which yields the paths matching a pathname pattern.
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_glob.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ def glob(self, *parts, **kwargs):
pattern = os.path.join(*parts)
p = os.path.join(self.tempdir, pattern)
res = glob.glob(p, **kwargs)
self.assertEqual(list(glob.iglob(p, **kwargs)), res)
self.assertEqual(sorted(glob.iglob(p, **kwargs)), res)
bres = [os.fsencode(x) for x in res]
self.assertEqual(glob.glob(os.fsencode(p), **kwargs), bres)
self.assertEqual(list(glob.iglob(os.fsencode(p), **kwargs)), bres)
self.assertEqual(sorted(glob.iglob(os.fsencode(p), **kwargs)), bres)
return res

def assertSequencesEqual_noorder(self, l1, l2):
Expand Down