[Python-Dev] Updates to PEP 471, the os.scandir() proposal

Paul Moore p.f.moore at gmail.com
Wed Jul 9 22:57:57 CEST 2014

On 9 July 2014 21:24, Victor Stinner <victor.stinner at gmail.com> wrote:
> Example where you may sometimes need is_dir(), but not always
> ---
> for entry in os.scandir(path):
>   if ignore_entry(entry.name):
>      # this entry is not interesting, lstat_result is useless here
>      continue
>   if entry.is_dir():  # fetch required data if needed
>      continue
>   ...
> ---

That is an extremely good point, and articulates why I've always been
a bit uncomfortable with the whole ensure_stat idea.

> I don't understand why you are all focused on handling os.stat() and
> os.lstat() errors. See for example the os.walk() function which is an
> old function (python 2.6!): it doesn't catch erros on isdir(), even if
> it has an onerror parameter... It only handles errors on listdir().
> IMO errors on os.stat() and os.lstat() are very rare under very
> specific conditions. The most common case is that you can get the
> status if you can list files.

Personally, I'm only focused on it as a response to others feeling
it's important. I'm on Windows, where there are no extra stat calls,
so all *I* care about is having an API that deals with the use cases
others are concerned about without making it too hard for me to use it
on Windows where I don't have to worry about all this.

If POSIX users come to a consensus that error handling doesn't need
special treatment, I'm more than happy to go back to the PEP version.
(Much as previously happened with the race condition debate).


More information about the Python-Dev mailing list