[Python-ideas] PEP 428 and is_file [was Re: PEP: Extended stat_result (First Draft)]

MRAB python at mrabarnett.plus.com
Tue May 7 13:26:07 CEST 2013


On 07/05/2013 11:46, Ethan Furman wrote:
> 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.
>
Isn't that a little like duck-typing? If I can't access it as a file,
it might as well not be a file (if it doesn't quack, then it is, for
all intents and purposes, not a duck, even if, in reality, it is).

> 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.
>




More information about the Python-ideas mailing list