[Python-ideas] find-like functionality in pathlib

Guido van Rossum guido at python.org
Tue Jan 5 19:02:41 EST 2016


On Tue, Jan 5, 2016 at 2:59 PM, Greg Ewing <greg.ewing at 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)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160105/59409693/attachment-0001.html>


More information about the Python-ideas mailing list