Skip to content

Commit 57bc982

Browse files
mjbommarclaude
andcommitted
gh-151788: Address review — drop perf comment, tame NEWS wording
- Remove the performance rationale from the inline comment; keep only the note explaining the OSError fallback (correctness, not performance). - Reword the NEWS entry to state the mechanism without magnitude claims. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 9ba9f68 commit 57bc982

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

Lib/http/server.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -902,10 +902,9 @@ def list_directory(self, path):
902902
for entry in entries:
903903
name = entry.name
904904
displayname = linkname = name
905-
# Append / for directories or @ for symbolic links. Use the cached
906-
# os.DirEntry methods to avoid a stat() per entry. Fall back to
907-
# False on OSError to mirror os.path.isdir()/islink(), whose result
908-
# would otherwise differ (e.g. a symlink to an unreadable target).
905+
# Append / for directories or @ for symbolic links. is_dir() and
906+
# is_symlink() can raise OSError where os.path.isdir()/islink()
907+
# return False, so fall back to False to keep the same behavior.
909908
try:
910909
is_dir = entry.is_dir()
911910
except OSError:
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
:class:`http.server.SimpleHTTPRequestHandler` now builds directory listings
2-
with :func:`os.scandir` instead of :func:`os.listdir` followed by an
3-
:func:`os.stat` call per entry. This improves the performance of
4-
:meth:`~http.server.SimpleHTTPRequestHandler.list_directory` on systems with
5-
slow ``stat`` calls, such as network filesystems.
1+
:class:`http.server.SimpleHTTPRequestHandler` now uses :func:`os.scandir`
2+
instead of :func:`os.listdir` to build directory listings, avoiding an
3+
:func:`os.stat` call per entry. This can improve
4+
:meth:`~http.server.SimpleHTTPRequestHandler.list_directory` performance where
5+
``stat`` calls are slow.

0 commit comments

Comments
 (0)