[Python-Dev] pathlib and issue 11406 (a directory iterator returning stat-like info)

Antoine Pitrou solipsis at pitrou.net
Sun Nov 24 23:44:34 CET 2013

On Mon, 25 Nov 2013 11:20:08 +1300
Ben Hoyt <benhoyt at gmail.com> wrote:
> This mainly depends on how Path is going to cache stat information. If
> it caches it, then this will just work. Sounds like Guido's opinion
> was that both cached and uncached use cases are important, but that it
> should be very clear which one you're getting. I personally like the
> .stat() and .restat() idea.

Right now, pathlib doesn't cache. Guido decided it was safer to start
off like that, and perhaps later we can add some optional caching.

One reason caching didn't go in is that it's not clear which API is
best. Working on pluggin scandir() into pathlib would actually help
choosing a stat-caching API.

(or, rather, lstat-caching...)

> The other related thing is that DirEntry only provides .lstat(),
> because it's providing stat-like info without following links.

Path.is_dir() and friends use stat(), i.e. they inform you about
whether a symlink's target is a directory (not the symlink itself).  Of
course, if the DirEntry says the path is a symlink, Path.is_dir() could
then run stat() to find out about the target.

Do you plan to propose scandir() for inclusion in the stdlib?



More information about the Python-Dev mailing list