Skip to content

gh-146646: Document that glob functions suppress OSError#147996

Open
WYSIATI wants to merge 1 commit intopython:mainfrom
WYSIATI:doc-glob-oserror-suppression
Open

gh-146646: Document that glob functions suppress OSError#147996
WYSIATI wants to merge 1 commit intopython:mainfrom
WYSIATI:doc-glob-oserror-suppression

Conversation

@WYSIATI
Copy link
Copy Markdown

@WYSIATI WYSIATI commented Apr 2, 2026

Summary

  • Add notes to glob.glob() and glob.iglob() documentation that OSError exceptions raised from scanning the filesystem are silently suppressed
  • This includes PermissionError when accessing directories without read permission
  • The pathlib.Path.glob() docs already document this behavior (added in 3.13 via a versionchanged note), but the glob module docs did not mention it

As @vstinner noted in the issue, the glob module ignores all OSError errors (not just access errors) — for example, _iterdir() wraps its scanner in except OSError: return.


📚 Documentation preview 📚: https://cpython-previews--147996.org.readthedocs.build/

Copy link
Copy Markdown
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is about pathlib.Path.glob() and pathlib.Path.rglob(). Can you also update their documentation?

@WYSIATI
Copy link
Copy Markdown
Author

WYSIATI commented Apr 8, 2026

The issue is about pathlib.Path.glob() and pathlib.Path.rglob(). Can you also update their documentation?

Thanks @vstinner for the review, pathlib.Path.glob() already has this documented as a versionchanged:: 3.13 note. Path.rglob() doesn't though — I'll add a matching note there and update the NEWS entry.

@WYSIATI WYSIATI requested a review from barneygale as a code owner April 8, 2026 02:06
.. versionchanged:: 3.13
Any :exc:`OSError` exceptions raised from scanning the filesystem are
suppressed. In previous versions, such exceptions are suppressed in many
cases, but not all.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you copy the note from the glob module to pathlib .glob() and .rglob() methods? IMO it's worth it to repeat the information (and mention PermissionError).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, let me do a quick update

The paths are returned in no particular order.
If you need a specific order, sort the results.

.. note::
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to move the note below, just before "audit-event".

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed, is current doc looking good to you?

@WYSIATI WYSIATI force-pushed the doc-glob-oserror-suppression branch from 4a8f892 to 9f88a5e Compare April 8, 2026 10:34
Copy link
Copy Markdown
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid git push --force, it makes reviews harder to follow.

.. seealso::
:ref:`pathlib-pattern-language` and :meth:`Path.glob` documentation.

.. note::
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The note should be moved the seealso paragraph.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants