Why exception from os.path.exists()?

Marko Rauhamaa marko at pacujo.net
Wed Jun 13 03:10:03 EDT 2018


"Peter J. Holzer" <hjp-python at hjp.at>:

> On 2018-06-11 12:24:54 +0000, Steven D'Aprano wrote:
>> It also 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. 
>> 
>> You know... like strings with NUL in them.

Nice catch!

> Ok. I missed that. So either the documentation or the implementation
> should be fixed. 
>
> In any case, if the implementation is changed, I still think that
> OSError(ENOENT) is wrong. It would have to be OSError(None, "embedded
> null byte"), or, if that is not possible (I haven't checked)
> OSError(EINVAL, "embedded null byte"), although that is slightly
> misleading (it implies that the OS returned EINVAL, which it didn't).

You say "misleading", I say "abstracting".

> The same check for NUL is also in other functions (e.g. open()), so
> those would have to be changed as well.

Maybe.

> I wasn't entirely clear here. What I meant is that POSIX systems, as a
> group, provide no such way.

I still don't see how POSIX is directly relevant here.


Marko



More information about the Python-list mailing list