[Python-Dev] Remaining decisions on PEP 471 -- os.scandir()
victor.stinner at gmail.com
Mon Jul 21 17:57:12 CEST 2014
2014-07-20 18:50 GMT+02:00 Antoine Pitrou <antoine at python.org>:
> Have you tried modifying importlib's _bootstrap.py to use scandir() instead
> of listdir() + stat()?
IMO the current os.scandir() API does not fit importlib requirements.
importlib usually wants fresh data, whereas DirEntry cache cannot be
invalidated. It's probably possible to cache some os.stat() result in
importlib, but it looks like it requires a non trivial refactoring of
the code. I don't know importlib enough to suggest how to change it.
There are many open isssues related to stat() in importlib, I found these ones:
By the way, DirEntry constructor is not documented in the PEP. Should
we document it? It might be a way to "invalidate the cache":
entry = DirEntry(os.path.dirname(entry.path), entry.name)
Maybe it is an abuse of the API. A clear_cache() method would be less
ugly :-) But maybe Ben Hoyt does not want to promote keeping DirEntry
for a long time?
Another question: should we expose DirEntry type directly in the os
More information about the Python-Dev