[Python-Dev] PEP 428: stat caching undesirable?

Charles-François Natali cf.natali at gmail.com
Wed May 1 14:50:07 CEST 2013


> 3) Leave it up to performance critical code, such as the import
> machinery, or walkdirs that Nick mentioned, to do their own caching, and
> simplify the filepath API for the simple case.
>
> But one can still make life easier for code like that, by adding
> is_file() and friends on the stat result object as I suggested.

+1 from me.
PEP 428 goes in the right direction with a distinction between "pure"
path and "concrete" path. Pure path support syntactic operations,
whereas I would expect concrete paths to actually access the file
system. Having a method like restat() is a hint that something's
wrong, I'm convinced this will bite some people.

I'm also be in favor of having a wrapper class around os.stat() result
which would export utility methods such as is_file()/is_directory()
and owner/group, etc attributes.

That way, the default behavior would be correct, and this helper class
would make it easier for users like walkdir() to implement their own
caching.

As an added benefit, this would make path objects actually immutable,
which is always a good thing (simpler, and you get thread-safety for
free).


More information about the Python-Dev mailing list