From: Barney Gale Date: Thu, 20 Jan 2022 19:20:00 +0000 (+0000) Subject: bpo-46316: optimize `pathlib.Path.iterdir()` (GH-30501) X-Git-Tag: v3.11.0a5~195 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a1c88414926610a3527398a478c3e63c531dc742;p=thirdparty%2FPython%2Fcpython.git 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. --- diff --git a/Lib/pathlib.py b/Lib/pathlib.py index f1a33178e295..04b321b9ccf1 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -1013,9 +1013,6 @@ class Path(PurePath): result for the special paths '.' and '..'. """ for name in self._accessor.listdir(self): - if name in {'.', '..'}: - # Yielding a path object for these makes little sense - continue yield self._make_child_relpath(name) def glob(self, pattern): diff --git a/Misc/NEWS.d/next/Library/2022-01-09-15-04-56.bpo-46316.AMTyd0.rst b/Misc/NEWS.d/next/Library/2022-01-09-15-04-56.bpo-46316.AMTyd0.rst new file mode 100644 index 000000000000..09acb77855f1 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-01-09-15-04-56.bpo-46316.AMTyd0.rst @@ -0,0 +1 @@ +Optimize :meth:`pathlib.Path.iterdir` by removing an unnecessary check for special entries.