classification
Title: pathlib.Path('/').mkdir() raises wrong error type
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.7, Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: Daniel Lepage, eryksun, pitrou, serhiy.storchaka
Priority: normal Keywords:

Created on 2015-12-05 03:48 by Daniel Lepage, last changed 2017-03-24 19:50 by serhiy.storchaka. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 805 merged serhiy.storchaka, 2017-03-24 17:19
PR 806 merged serhiy.storchaka, 2017-03-24 19:00
PR 807 merged serhiy.storchaka, 2017-03-24 19:15
Messages (7)
msg255916 - (view) Author: Daniel Lepage (Daniel Lepage) Date: 2015-12-05 03:48
pathlib.Path('/').mkdir() raises an IsADirectoryError instead of a FileExistsError.
msg255956 - (view) Author: Daniel Lepage (Daniel Lepage) Date: 2015-12-05 14:39
It looks like this is an OSX-specific behavior, and not a python problem:
 $ mkdir .
mkdir: .: File exists
 $ mkdir /
mkdir: /: Is a directory
msg255958 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2015-12-05 14:46
The mkdir method needs a fix similar to what was done for issue 25583. For example, currently on Windows the exist_ok option doesn't handle the PermissionError raised when [accidentally] trying to create the root directory:

    >>> pathlib.Path('C:/').mkdir(exist_ok=True)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Program Files\Python 3.5\lib\pathlib.py", line 1199, in mkdir
        self._accessor.mkdir(self, mode)
      File "C:\Program Files\Python 3.5\lib\pathlib.py", line 371, in wrapped
        return strfunc(str(pathobj), *args)
    PermissionError: [WinError 5] Access is denied: 'C:\\'
msg290100 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-03-24 17:21
I can't test on Windows and OSX but I suppose PR 805 fixes both issues.
msg290105 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-03-24 18:51
New changeset af7b9ec5c855366feef4c67dc492d64b3baf84ca by Serhiy Storchaka in branch 'master':
bpo-25803: Avoid incorrect errors raised by Path.mkdir(exist_ok=True) (#805)
https://github.com/python/cpython/commit/af7b9ec5c855366feef4c67dc492d64b3baf84ca
msg290112 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-03-24 19:46
New changeset 8c8785b2f8e4048cef350f89c686266f4519b67c by Serhiy Storchaka in branch '3.6':
bpo-25803: Avoid incorrect errors raised by Path.mkdir(exist_ok=True)… (#806)
https://github.com/python/cpython/commit/8c8785b2f8e4048cef350f89c686266f4519b67c
msg290113 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-03-24 19:46
New changeset 1fc1f8d7f737f80a1ee5ea37b9781c0a790102b2 by Serhiy Storchaka in branch '3.5':
bpo-25803: Avoid incorrect errors raised by Path.mkdir(exist_ok=True) (#805) (#807)
https://github.com/python/cpython/commit/1fc1f8d7f737f80a1ee5ea37b9781c0a790102b2
History
Date User Action Args
2017-03-24 19:50:35serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2017-03-24 19:46:48serhiy.storchakasetmessages: + msg290113
2017-03-24 19:46:27serhiy.storchakasetmessages: + msg290112
2017-03-24 19:15:33serhiy.storchakasetpull_requests: + pull_request712
2017-03-24 19:00:24serhiy.storchakasetpull_requests: + pull_request711
2017-03-24 18:51:55serhiy.storchakasetmessages: + msg290105
2017-03-24 17:21:39serhiy.storchakasetversions: + Python 3.7
nosy: + serhiy.storchaka

messages: + msg290100

assignee: serhiy.storchaka
stage: patch review
2017-03-24 17:19:53serhiy.storchakasetpull_requests: + pull_request710
2015-12-05 17:16:39eryksunsetnosy: + pitrou

versions: + Python 3.6
2015-12-05 14:46:51eryksunsetnosy: + eryksun
messages: + msg255958
2015-12-05 14:39:57Daniel Lepagesetmessages: + msg255956
2015-12-05 03:48:12Daniel Lepagecreate