[Python-Dev] Issue 11406: adding os.scandir(), a directory iterator returning stat-like info
benhoyt at gmail.com
Tue May 14 00:50:13 CEST 2013
> OK, you got me! I'm now convinced that a property is a bad idea.
> I still like to annotate that the function may return a cached value.
> Perhaps lstat() could require an argument?
> def lstat(self, cached):
> if not cached or self._lstat is None:
> self._lstat = os.lstat(...)
> return self._lstat
Hmm, I'm just not sure I like the API. Setting cached to True to me
would imply it's only ever going to come from the cache (i.e., just
return self._lstat). Also, isdir() etc have the same issue, so if
you're going this route, their signatures would need this too.
The DirEntry instance is really a cached value in itself. ".name" is
cached, ".dirent" is cached, and the methods return cached if they
can. That's more or less the point of the object. But you have a fair
point, and this would need to be explicit in the documentation.
>> True. My isdir/isfile/islink implementations should catch any OSError
>> from the lstat() and return False (like os.path.isdir etc do). But
>> then calling code still doesn't need try/excepts around the isdir()
>> calls. This is how os.walk() is implemented -- there's no extra error
>> handling around the isdir() call.
> You could take the opportunity and take the 'file was deleted' case into
> account. I admit it has a very low priority. Please regard the case for
> bonus points only. ;)
>> Sure. I'm primarily a Windows dev, so not too familiar with all the
>> fancy stat* functions. But what you're saying makes sense.
> I'm glad to be of assistance! The feature is new (added in 3.3) and is
> available on most POSIX platforms.
> If you need any help or testing please feel free to ask me. I really
> like to get this feature into 3.4.
More information about the Python-Dev