Why exception from os.path.exists()?

Peter J. Holzer hjp-python at hjp.at
Sun Jun 10 17:57:35 EDT 2018


On 2018-06-11 00:28:11 +0300, Marko Rauhamaa wrote:
> Barry Scott <barry at barrys-emacs.org>:
> > Singling out os.path.exists as a special case I do think is
> > reasonable.
> 
> I don't think anyone has proposed that. While I brought up
> os.path.exists() in my bug report, os.path.isfile(), os.path.isdir() etc
> should obviously be addressed simultaneously.

Yes.

> It may even be that the fix needs to go to os.stat(). That's for the
> Python gods to decide.

I'm not a Python god, but I don't think os.stat() should be changed.
That already throws different exceptions for different errors:

>>> os.stat("nix")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'nix'
>>> os.stat("/lost+found/foo")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
PermissionError: [Errno 13] Permission denied: '/lost+found/foo'
>>> os.stat("\0")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: embedded null byte

I think this is worth keeping, and "I couldn't pass that file name to
the OS" is a different error than "the OS told me the file doesn't
exist", so I think it should be a different exception.

        hp

-- 
   _  | Peter J. Holzer    | we build much bigger, better disasters now
|_|_) |                    | because we have much more sophisticated
| |   | hjp at hjp.at         | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20180610/d25e9b76/attachment.sig>


More information about the Python-list mailing list