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

Paul Moore p.f.moore at gmail.com
Wed Jul 9 19:10:29 CEST 2014


On 9 July 2014 14:22, Ben Hoyt <benhoyt at gmail.com> wrote:
> One issue with option #2 that I just realized -- does scandir yield
> the entry at all if there's a stat error? It can't really, because the
> caller will except the .lstat attribute to be set (assuming he asked
> for type='lstat') but it won't be. Is effectively removing these
> entries just because the stat failed a problem? I kind of think it is.
> If so, is there a way to solve it with option #2?

So the issue is that you need to do a stat but it failed. You have
"whatever the OS gave you", but can't get anything more. This is only
an issue on POSIX, where the original OS call doesn't give you
everything, so it's fine, those POSIX people can just learn to cope
with their broken OS, right? :-)

More seriously, why not just return a DirEntry that says it's a file
with a stat entry that's all zeroes? That seems pretty harmless. And
the onerror function will be called, so if it is inappropriate the
application can do something. Maybe it's worth letting onerror return
a boolean that says whether to skip the entry, but that's as far as
I'd bother going.

It's a close call, but I think option #2 still wins (just) for me.

Paul


More information about the Python-Dev mailing list