Message 320493 - Python tracker

Message320493

Author emilyemorehouse
Recipients CarlAndersson, emilyemorehouse
Date 2018-06-26.14:35:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1530023720.26.0.56676864532.issue33968@psf.upfronthosting.co.za>
In-reply-to
Content
This is an interesting behavior to note. I think the current behavior makes the most sense, as it corresponds to the OS-level errors that you get from running the same operations.

Interestingly, at least on Unix-based file systems, we get different error messages but the same behavior when using "" vs "." as our target:

[linux]$ mkdir ""
mkdir: cannot create directory ‘’: No such file or directory
[linux]$ mkdir .
mkdir: cannot create directory ‘.’: File exists

[mac]$ mkdir ""
mkdir: .: No such file or directory
[mac]$ mkdir .
mkdir: .: File exists

Both os.mkdir and os.makedirs follow (only os.mkdir is included as the traceback is cleaner, but they raise the same errors):
>>> os.mkdir("")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: ''
>>> os.mkdir(".")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FileExistsError: [Errno 17] File exists: '.'


Since on an OS level the only time "File exists" is returned is when using "." and not "", os.makedirs with exists_ok=True also follows:

>>> os.makedirs("", exist_ok=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/os.py", line 220, in makedirs
    mkdir(name, mode)
FileNotFoundError: [Errno 2] No such file or directory: ''
>>> os.makedirs(".", exist_ok=True)
>>>

Basically, the FileExistsError gets silenced, but FileNotFoundError is left alone. I can see how the differences are nuanced and not obvious though.


Unless you think there is a succinct and worthwhile way of adding this to the documentation, I think this issue can be closed.
History
Date User Action Args
2018-06-26 14:35:20emilyemorehousesetrecipients: + emilyemorehouse, CarlAndersson
2018-06-26 14:35:20emilyemorehousesetmessageid: <1530023720.26.0.56676864532.issue33968@psf.upfronthosting.co.za>
2018-06-26 14:35:20emilyemorehouselinkissue33968 messages
2018-06-26 14:35:20emilyemorehousecreate