GH-78722: Raise exceptions from pathlib.Path.iterdir() without delay.#107320
Merged
barneygale merged 1 commit intopython:mainfrom Sep 2, 2023
Merged
Conversation
…t delay. `pathlib.Path.iterdir()` now immediately raises any `OSError` exception from `os.listdir()`, rather than waiting until its result is iterated over.
Member
|
Wow. I'd forgotten I'd reviewed this change (or at least endorsed the proposal) when I was caught by surprise in jaraco/develop#26 (then #129871). That code was relying on the lazy exception behavior. I ended up working around the issue by relying on glob instead of iterdir to get the lenient behavior back. I don't see any mention of this change in "what's new for Python 3.13". Maybe there should be a mention of it. I'm now also a little skeptical of the value of this change. It shows that there are at least some cases where people might be relying on the late resolution of the error. We can discuss in the new issue. |
tumidi
added a commit
to questionpy-org/questionpy-sdk
that referenced
this pull request
Jul 23, 2025
In Python 3.13, `iterdir()` raises exceptions immediately instead of lazily. This change forces early evaluation to ensure consistent behavior across Python versions. Ref: python/cpython#107320
tumidi
added a commit
to questionpy-org/questionpy-sdk
that referenced
this pull request
Aug 21, 2025
In Python 3.13, `iterdir()` raises exceptions immediately instead of lazily. This change forces early evaluation to ensure consistent behavior across Python versions. Ref: python/cpython#107320
tumidi
added a commit
to questionpy-org/questionpy-sdk
that referenced
this pull request
Aug 21, 2025
In Python 3.13, `iterdir()` raises exceptions immediately instead of lazily. This change forces early evaluation to ensure consistent behavior across Python versions. Ref: python/cpython#107320
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pathlib.Path.iterdir()now immediately raises anyOSErrorexception fromos.listdir(), rather than waiting until its result is iterated over.