[Python-ideas] PEP 428 and is_file [was Re: PEP: Extended stat_result (First Draft)]
Ethan Furman
ethan at stoneleaf.us
Tue May 7 12:46:08 CEST 2013
On 05/07/2013 03:18 AM, Antoine Pitrou wrote:
> Le Tue, 07 May 2013 12:05:33 +0200, Pieter Nagel a écrit :
>>
>> Speaking of which, your current implementation os PEP 428 raises
>> exceptions when quering is_file() or is_dir() on nonexistent paths. Is
>> that by design, or an oversight?
>
> To be honest I haven't given much thought to it, but I guess they
> could also swallow exceptions.
+1
>With the current default caching
> behaviour, it is not detrimental to write `path.exists() and
> path.is_file()`, though.
It may not be detrimental to the code, but it is to the user (at least to me ;). If the path doesn't exist, it's
obviously not a file. Why should I have to do two checks instead of one? It would be like having to guard every ==
with a try/except NotImplementedError and substituting False.
And yes, I realize that .exists() would tell be the path is not a file, but .exists is not the only reason why it might
not be a file, which means in the general case I would have to do two checks.
--
~Ethan~
More information about the Python-ideas
mailing list