This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author steven.daprano
Recipients eric.smith, eryksun, mrabarnett, pacujo, r.david.murray, serhiy.storchaka, steven.daprano
Date 2018-06-14.13:25:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1528982732.98.0.947875510639.issue33721@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2018-06-14 13:25:33steven.dapranosetrecipients: + steven.daprano, eric.smith, mrabarnett, r.david.murray, serhiy.storchaka, eryksun, pacujo
2018-06-14 13:25:32steven.dapranosetmessageid: <1528982732.98.0.947875510639.issue33721@psf.upfronthosting.co.za>
2018-06-14 13:25:32steven.dapranolinkissue33721 messages
2018-06-14 13:25:32steven.dapranocreate