[issue33721] os.path.exists() ought to return False if pathname contains NUL
Steven D'Aprano
report at bugs.python.org
Thu Jun 14 09:25:32 EDT 2018
Steven D'Aprano <steve+python at pearwood.info> added the comment:
Eryk Sun says:
> It has to be a ValueError since the error is an invalid parameter at the Python level.
How does the first follow from the second?
Strings with NULs in them aren't errors or invalid parameters at the Python level, and they are legal file names in at least some file systems.
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.
I don't believe there is any good reason for singling out NULs for a different exception from other invalid file names like ">" on NTFS.
This ought to be an OSError for functions like os.stat and False for os.path.exists, as Jython does.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33721>
_______________________________________
More information about the Python-bugs-list
mailing list