<p dir="ltr"><br>
On 1 Jul 2014 07:31, "Victor Stinner" <<a href="mailto:victor.stinner@gmail.com">victor.stinner@gmail.com</a>> wrote:<br>
><br>
> 2014-07-01 15:00 GMT+02:00 Ben Hoyt <<a href="mailto:benhoyt@gmail.com">benhoyt@gmail.com</a>>:</p>
<p dir="ltr">> > 2) Nick Coghlan's proposal on the previous thread<br>
> > (<a href="https://mail.python.org/pipermail/python-dev/2014-June/135261.html">https://mail.python.org/pipermail/python-dev/2014-June/135261.html</a>)<br>
> > suggesting an ensure_lstat keyword param to scandir if you need the<br>
> > lstat_result value<br>
><br>
> I don't like this idea because it makes error handling more complex.<br>
> The syntax to catch exceptions on an iterator is verbose (while: try:<br>
> next() except ...).</p>
<p dir="ltr">Actually, we may need to copy the os.walk API and accept an "onerror" callback as a scandir argument. Regardless of whether or not we have "ensure_lstat", the iteration step could fail, so I don't believe we can just transfer the existing approach of catching exceptions from the listdir call.</p>

<p dir="ltr">> Whereas calling os.lstat(entry.fullname()) is explicit and it's easy<br>
> to surround it with try/except.<br>
><br>
><br>
> > .lstat_result being None sometimes (on POSIX),<br>
><br>
> Don't do that, it's not how Python handles portability. We use hasattr().</p>
<p dir="ltr">That's not true in general - we do either, depending on context. </p>
<p dir="ltr">With the addition of an os.walk style onerror callback, I'm still in favour of a "get_lstat" flag (tweaked as Ben suggests to always be None unless requested, so Windows code is less likely to be inadvertently non-portable)<br>
</p>
<p dir="ltr">> > would it ever really happen that readdir() would succeed but an os.stat() immediately after would fail?<br>
><br>
> Yes, it can happen. The filesystem is system-wide and shared by all<br>
> users. The file can be deleted.</p>
<p dir="ltr">We need per-iteration error handling for the readdir call anyway, so I think an onerror callback is a better option than dropping the ability to easily obtain full stat information as part of the iteration.</p>

<p dir="ltr">Cheers,<br>
Nick.</p>