Skip to content

GH-78722: Raise exceptions from pathlib.Path.iterdir() without delay. #107320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

barneygale
Copy link
Contributor

@barneygale barneygale commented Jul 26, 2023

pathlib.Path.iterdir() now immediately raises any OSError exception from os.listdir(), rather than waiting until its result is iterated over.

…t delay.

`pathlib.Path.iterdir()` now immediately raises any `OSError`
exception from `os.listdir()`, rather than waiting until its
result is iterated over.
@jaraco
Copy link
Member

jaraco commented Feb 8, 2025

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.

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

Successfully merging this pull request may close these issues.

3 participants