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

Pieter Nagel pieter at nagel.co.za
Tue May 7 12:05:33 CEST 2013


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

And even if os.path.isfile is arguably incorrect in this situation, is
it likely to be fixed? If not, should new code, like my proposal or your
PEP 428, follow its incorrect example or do it correctly, but
differently?

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?

-- 
Pieter Nagel





More information about the Python-ideas mailing list