[Python-Dev] Updates to PEP 471, the os.scandir() proposal
ethan at stoneleaf.us
Tue Jul 8 21:02:56 CEST 2014
On 07/08/2014 11:05 AM, Ben Hoyt wrote:
>> Only exposing what the OS provides for free will make the API too difficult
>> to use in the common case. But is there a nice way to expand the API that
>> will allow the user who is trying to avoid extra expense know what
>> information is already available?
>> Even if the initial version doesn't have a way to check what information is
>> there for free, ensuring there is a clean way to add this in the future
>> would be really nice.
> We could easily add ".had_type" and ".had_lstat" properties (not sure
> on the names), that would be true if the is_X information and lstat
> information was fetched, respectively. Basically both would always be
> True on Windows, but on POSIX only had_type would be True d_type is
> present and != DT_UNKNOWN.
> I don't feel this is actually necessary, but it's not hard to add.
Better to just have the attributes be None if they were not fetched. None is better than hasattr anyway, at least in
the respect of not having to catch exceptions to function properly.
More information about the Python-Dev