On Tue, Jan 5, 2016 at 2:59 PM, Greg Ewing <greg.ewing@canterbury.ac.nz> wrote:
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.

Well, Path.stat() is already defined and returns the same type of object that os.stat() returns, and I don't think we should change that.

We could add a new method that does this, but as long as it inherits from Path it wouldn't really address the issue with objects being == to each other but holding different stat info.
 
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.

I presume you are proposing a new Path.scandir() method -- the existing os.scandir() method already returns DirEntry objects which we really don't want to change at this point.

--
--Guido van Rossum (python.org/~guido)