[Python-ideas] PEP: Extended stat_result (First Draft)

Antoine Pitrou solipsis at pitrou.net
Tue May 7 12:18:33 CEST 2013


Le Tue, 07 May 2013 12:05:33 +0200,
Pieter Nagel <pieter at nagel.co.za> a écrit :
> On Tue, 2013-05-07 at 11:13 +0200, Antoine Pitrou wrote:
> 
> > However, I should point out that FileNotFoundError is not the only
> > error that may be raised:
> > 
> >   >>> os.stat("/proc/1/fd/1")
> >   Traceback (most recent call last):
> >     File "<stdin>", line 1, in <module>
> >   PermissionError: [Errno 13] Permission denied: '/proc/1/fd/1'
> 
> This raises the question of whether the current os.path.isfile etc.
> behaviour is correct.
> 
> Currently it swallows any os.error and returns False. But in a
> situation like the above, is not necessarily true that the path is
> not a file just because you don't have permission to interrogate it..

Well, at least it's not usable as a file by the current user. Which is
generally the point :)
But isfile() and friends are higher-level helpers, it makes more sense
for them to swallow an exception than os.stat() (IMHO).

> 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. With the current default caching
behaviour, it is not detrimental to write `path.exists() and
path.is_file()`, though.

Regards

Antoine.





More information about the Python-ideas mailing list