From a1c88414926610a3527398a478c3e63c531dc742 Mon Sep 17 00:00:00 2001 From: Barney Gale Date: Thu, 20 Jan 2022 19:20:00 +0000 Subject: 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. --- Lib/pathlib.py | 3 --- Misc/NEWS.d/next/Library/2022-01-09-15-04-56.bpo-46316.AMTyd0.rst | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2022-01-09-15-04-56.bpo-46316.AMTyd0.rst diff --git a/Lib/pathlib.py b/Lib/pathlib.py index f1a3317..04b321b 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 0000000..09acb77 --- /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. -- cgit v0.12