Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Undo change to iterdir()
  • Loading branch information
barneygale committed Dec 18, 2023
commit 352ad99117648f36748e1e54871ab6383e5a2fd5
3 changes: 1 addition & 2 deletions Lib/pathlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,7 @@ def iterdir(self):
The children are yielded in arbitrary order, and the
special entries '.' and '..' are not included.
"""
with os.scandir(self) as entries:
return iter([self._make_child_entry(entry) for entry in entries])
return (self._make_child_relpath(name) for name in os.listdir(self))

def _scandir(self):
return os.scandir(self)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Speed up :meth:`pathlib.Path.iterdir` and :meth:`~pathlib.Path.glob` by
using :attr:`os.DirEntry.path` where possible.
Speed up :meth:`pathlib.Path.glob` by using :attr:`os.DirEntry.path` where possible.