Skip to content

Commit 9f88a5e

Browse files
committed
gh-146646: Document that glob functions suppress OSError
1 parent 7563585 commit 9f88a5e

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

Doc/library/glob.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ The :mod:`!glob` module defines the following functions:
8383
This function may return duplicate path names if *pathname*
8484
contains multiple "``**``" patterns and *recursive* is true.
8585

86+
.. note::
87+
Any :exc:`OSError` exceptions raised from scanning the filesystem are
88+
suppressed. This includes :exc:`PermissionError` when accessing
89+
directories without read permission.
90+
8691
.. versionchanged:: 3.5
8792
Support for recursive globs using "``**``".
8893

@@ -106,6 +111,11 @@ The :mod:`!glob` module defines the following functions:
106111
This function may return duplicate path names if *pathname*
107112
contains multiple "``**``" patterns and *recursive* is true.
108113

114+
.. note::
115+
Any :exc:`OSError` exceptions raised from scanning the filesystem are
116+
suppressed. This includes :exc:`PermissionError` when accessing
117+
directories without read permission.
118+
109119
.. versionchanged:: 3.5
110120
Support for recursive globs using "``**``".
111121

Doc/library/pathlib.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,11 @@ Reading directories
13511351
``False``, this method follows symlinks except when expanding "``**``"
13521352
wildcards. Set *recurse_symlinks* to ``True`` to always follow symlinks.
13531353

1354+
.. note::
1355+
Any :exc:`OSError` exceptions raised from scanning the filesystem are
1356+
suppressed. This includes :exc:`PermissionError` when accessing
1357+
directories without read permission.
1358+
13541359
.. audit-event:: pathlib.Path.glob self,pattern pathlib.Path.glob
13551360

13561361
.. versionchanged:: 3.12
@@ -1380,6 +1385,11 @@ Reading directories
13801385
.. seealso::
13811386
:ref:`pathlib-pattern-language` and :meth:`Path.glob` documentation.
13821387

1388+
.. note::
1389+
Any :exc:`OSError` exceptions raised from scanning the filesystem are
1390+
suppressed. This includes :exc:`PermissionError` when accessing
1391+
directories without read permission.
1392+
13831393
.. audit-event:: pathlib.Path.rglob self,pattern pathlib.Path.rglob
13841394

13851395
.. versionchanged:: 3.12
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Document that :func:`glob.glob`, :func:`glob.iglob`,
2+
:meth:`pathlib.Path.glob`, and :meth:`pathlib.Path.rglob` silently suppress
3+
:exc:`OSError` exceptions raised from scanning the filesystem.

0 commit comments

Comments
 (0)