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

`pathlib.Path.iterdir()` now immediately raises any `OSError`
exception from `os.listdir()`, rather than waiting until its
result is iterated over.
This commit is contained in:
Barney Gale 2023-09-02 16:08:03 +01:00 committed by GitHub
parent 594b00057e
commit bdc3c884cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 3 deletions

View file

@ -1766,7 +1766,7 @@ class PathTest(unittest.TestCase):
# __iter__ on something that is not a directory.
p = self.cls(BASE, 'fileA')
with self.assertRaises(OSError) as cm:
next(p.iterdir())
p.iterdir()
# ENOENT or EINVAL under Windows, ENOTDIR otherwise
# (see issue #12802).
self.assertIn(cm.exception.errno, (errno.ENOTDIR,