Skip to content

Commit a1c8841

Browse files
authored
bpo-46316: optimize pathlib.Path.iterdir() (GH-30501)
`os.listdir()` doesn't return entries for `.` or `..`, so we don't need to check for them here.
1 parent c02e860 commit a1c8841

File tree

2 files changed

+1
-3
lines changed

2 files changed

+1
-3
lines changed

Lib/pathlib.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,9 +1013,6 @@ def iterdir(self):
10131013
result for the special paths '.' and '..'.
10141014
"""
10151015
for name in self._accessor.listdir(self):
1016-
if name in {'.', '..'}:
1017-
# Yielding a path object for these makes little sense
1018-
continue
10191016
yield self._make_child_relpath(name)
10201017

10211018
def glob(self, pattern):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Optimize :meth:`pathlib.Path.iterdir` by removing an unnecessary check for special entries.

0 commit comments

Comments
 (0)