GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GH-78722: Raise exceptions from `pathlib.Path.iterdir()` without delay. by barneygale · Pull Request #107320 · python/cpython

Conversation

@barneygale

@barneygale barneygale commented Jul 26, 2023 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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

  • Issue: pathlib.Path.iterdir doesn't raise an exception until you start iterating #78722

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@barneygale
pythonGH-78722: Raise exceptions from pathlib.Path.iterdir() withou…
4d552aa
…t delay.

`pathlib.Path.iterdir()` now immediately raises any `OSError`
exception from `os.listdir()`, rather than waiting until its
result is iterated over.
@barneygale barneygale added the topic-pathlib label Jul 26, 2023
@barneygale barneygale assigned jaraco Jul 26, 2023
@bedevere-bot bedevere-bot mentioned this pull request Jul 26, 2023
pathlib.Path.iterdir doesn't raise an exception until you start iterating #78722
Closed
@bedevere-bot bedevere-bot added the awaiting core review label Jul 26, 2023
@barneygale
barneygale requested a review from jaraco July 26, 2023 21:56
@barneygale barneygale unassigned jaraco Jul 26, 2023
@barneygale
barneygale merged commit bdc3c88 into python:main Sep 2, 2023
@bedevere-bot bedevere-bot removed the awaiting core review label Sep 2, 2023
@tomasr8 tomasr8 mentioned this pull request Feb 8, 2025
Pathlib.iterdir semantics change dramatically under Python 3.13 #129871
Open
@jaraco

jaraco commented Feb 8, 2025

Copy link
Copy Markdown
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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tumidi added a commit to questionpy-org/questionpy-sdk that referenced this pull request Jul 23, 2025
@tumidi
fix: account for iterdir() behavior change in Python 3.13
4511baa
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
@tumidi
fix: account for iterdir() behavior change in Python 3.13
bc2d0fb
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
@tumidi
fix: account for iterdir() behavior change in Python 3.13
cbeda8f
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@jaraco jaraco Awaiting requested review from jaraco

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

topic-pathlib

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@barneygale @jaraco @bedevere-bot
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.