]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46316: optimize `pathlib.Path.iterdir()` (GH-30501)
authorBarney Gale <barney.gale@gmail.com>
Thu, 20 Jan 2022 19:20:00 +0000 (19:20 +0000)
committerGitHub <noreply@github.com>
Thu, 20 Jan 2022 19:20:00 +0000 (13:20 -0600)
`os.listdir()` doesn't return entries for `.` or `..`, so we don't need to
check for them here.

Lib/pathlib.py
Misc/NEWS.d/next/Library/2022-01-09-15-04-56.bpo-46316.AMTyd0.rst [new file with mode: 0644]

index f1a33178e2958ba45177b64b787338d115c0b6b6..04b321b9ccf1668e7fbc57685bc9f0b516f2c147 100644 (file)
@@ -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 (file)
index 0000000..09acb77
--- /dev/null
@@ -0,0 +1 @@
+Optimize :meth:`pathlib.Path.iterdir` by removing an unnecessary check for special entries.