[Python-ideas] find-like functionality in pathlib

Greg Ewing greg.ewing at canterbury.ac.nz
Tue Jan 5 17:59:49 EST 2016


Guido van Rossum wrote:
> I wonder if stat() caching shouldn't be made an orthogonal optional 
> feature of Path objects somehow; it keeps coming back as useful in 
> various cases even though we don't want to enable it by default.

Maybe path.stat() could return a PathWithStat object that
inherits from Path and can do everything that a Path can
do, but also contains cached stat info and has a suitable
set of attributes for accessing it.

This would make it clear at what point in time the info
is valid for, i.e. the moment you called stat(). It would
also provide an obvious way to refresh the info: calling
path_with_stat.stat() would give you a new PathWithStat
containing updated info.

Things like scandir could then return pre-populated
PathWithStat objects.

-- 
Greg


More information about the Python-ideas mailing list