pacujo <ma...@pacujo.net> added the comment:

Eryk Sun:
> I only meant that, as an honest error, it has to be ValueError. I didn't
> think about raising a fake OSError.
>
> Note that I didn't say the ValueError shouldn't be ignored by
> os.path.exists (et al). In the spirit of the current function, it
> probably should be ignored. For example, it returns False for paths that
> exist but are inaccessible.

For the original complaint of mine, catching ValueError would work. I
must say, though, that Steven's arguments for raising a fake OSError are
very convincing.

Steven D'Aprano:
> Jython does this:
> 
> >>> import os
> >>> os.path.exists('/tmp/foo\0bar')
> False
> >>> os.stat('/tmp/foo\0bar')
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> OSError: [Errno 2] No such file or directory: '/tmp/foo\x00bar'
> 
> 
> As far as I am concerned, raising ValueError is simply a bug. The
> documentation for the os module clearly states:
> 
>     All functions in this module raise OSError in the case of
>     invalid or inaccessible file names and paths, or other
>     arguments that have the correct type, but are not accepted
>     by the operating system.

Now the question is not anymore if and how CPython should be fixed but
if and how Jython should be fixed.

IMO, Jython is doing the right thing. If that is not true, then Jython
must be declared buggy.

> Maybe it could raise an InvalidFilename subclass of OSError. This
> could even handle some actual OS errors such as POSIX ENAMETOOLONG and
> Windows ERROR_INVALID_NAME, ERROR_BAD_PATHNAME, and
> ERROR_FILENAME_EXCED_RANGE.

Maybe. You'll still need OSError.errno to hold a true error value.

Marko

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue33721>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to