[issue39907] `pathlib.Path.iterdir()` wastes memory by using `os.listdir()` rather than `os.scandir()`
Barney Gale
report at bugs.python.org
Sun Mar 8 20:17:57 EDT 2020
New submission from Barney Gale <barney.gale at gmail.com>:
`pathlib.Path.iterdir()` uses `os.listdir()` rather than `os.scandir()`. I think this has a small performance cost, per PEP 471:
> It returns a generator instead of a list, so that scandir acts as a true iterator instead of returning the full list immediately.
As `scandir()` is already available from `_NormalAccessor` it's a simple patch to use `scandir()` instead.
----------
components: Library (Lib)
messages: 363689
nosy: barneygale
priority: normal
severity: normal
status: open
title: `pathlib.Path.iterdir()` wastes memory by using `os.listdir()` rather than `os.scandir()`
type: resource usage
versions: Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39907>
_______________________________________
More information about the Python-bugs-list
mailing list