Skip to content

gh-78722: Fixed, pathlib.Path.iterdir now throws an exception when path is not valid #8999

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1060,9 +1060,14 @@ def iterdir(self):
"""Iterate over the files in this directory. Does not yield any
result for the special paths '.' and '..'.
"""
#Below line throws FileNotFoundError if path is invalid
dirs = self._accessor.listdir(self)
return self._iterdirgen(dirs)

def _iterdirgen(self,dirs):
if self._closed:
self._raise_closed()
for name in self._accessor.listdir(self):
for name in dirs:
if name in {'.', '..'}:
# Yielding a path object for these makes little sense
continue
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Added code to make pathlib.Path.iterdir throw FileNotFoundError when path is
not valid