From df86064860af967b7fbc73f5c806f5ac9b8774c4 Mon Sep 17 00:00:00 2001 From: Chester Li Date: Thu, 2 Apr 2026 15:16:15 +0800 Subject: [PATCH] gh-146646: Document that glob functions suppress OSError Document that glob.glob() and glob.iglob() silently suppress any OSError exceptions raised while scanning the filesystem, such as PermissionError when accessing directories without read permission. The pathlib.Path.glob() docs already note this behavior (added in 3.13), but the glob module docs did not mention it. Co-Authored-By: Claude Opus 4.6 (1M context) --- Doc/library/glob.rst | 10 ++++++++++ .../2026-04-02-07-20-00.gh-issue-146646.GlobDoc1.rst | 2 ++ 2 files changed, 12 insertions(+) create mode 100644 Misc/NEWS.d/next/Documentation/2026-04-02-07-20-00.gh-issue-146646.GlobDoc1.rst diff --git a/Doc/library/glob.rst b/Doc/library/glob.rst index 52c44928153337..b24e4da7bc8c07 100644 --- a/Doc/library/glob.rst +++ b/Doc/library/glob.rst @@ -83,6 +83,11 @@ The :mod:`!glob` module defines the following functions: This function may return duplicate path names if *pathname* contains multiple "``**``" patterns and *recursive* is true. + .. note:: + Any :exc:`OSError` exceptions raised from scanning the filesystem are + suppressed. This includes :exc:`PermissionError` when accessing + directories without read permission. + .. versionchanged:: 3.5 Support for recursive globs using "``**``". @@ -106,6 +111,11 @@ The :mod:`!glob` module defines the following functions: This function may return duplicate path names if *pathname* contains multiple "``**``" patterns and *recursive* is true. + .. note:: + Any :exc:`OSError` exceptions raised from scanning the filesystem are + suppressed. This includes :exc:`PermissionError` when accessing + directories without read permission. + .. versionchanged:: 3.5 Support for recursive globs using "``**``". diff --git a/Misc/NEWS.d/next/Documentation/2026-04-02-07-20-00.gh-issue-146646.GlobDoc1.rst b/Misc/NEWS.d/next/Documentation/2026-04-02-07-20-00.gh-issue-146646.GlobDoc1.rst new file mode 100644 index 00000000000000..4bae68995c4ab3 --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2026-04-02-07-20-00.gh-issue-146646.GlobDoc1.rst @@ -0,0 +1,2 @@ +Document that :func:`glob.glob` and :func:`glob.iglob` silently suppress +:exc:`OSError` exceptions raised from scanning the filesystem.