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.

Title: pathlib Path.replace raises OSError when target exists
Type: behavior Stage:
Components: Documentation Versions: Python 3.8
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, pitrou, selik, serhiy.storchaka, xtreak
Priority: normal Keywords:

Created on 2020-04-14 03:36 by selik, last changed 2022-04-11 14:59 by admin.

Messages (3)
msg366363 - (view) Author: Michael Selik (selik) * Date: 2020-04-14 03:36
The pathlib module ``Path.replace(target)`` states that "If target points to an existing file or directory, it will be unconditionally replaced."  However, this does not appear to be true.  I experience an OSError ``[Errno 66] Directory not empty`` when attempting to ``replace`` to an existant target.

I see that others on StackOverflow encounter the same issue.  The top answer ignores the Python documentation and recommends removing the target directory before replacing.
msg366364 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2020-04-14 04:10
replace under the hood uses os.replace. The docs for os.replace indicate error for certain scenarios where target is a directory : . See also some difference between os.rename and os.replace :
msg366365 - (view) Author: Michael Selik (selik) * Date: 2020-04-14 04:45
The docs for ``os.replace`` says "If dst is a directory, OSError will be raised."  That's helpful, but the docs for ``pathlib.Path.replace`` make it seem like the target will be unconditionally replaced regardless of whether it's a file or directory.  Sure, there's the association of the two functions in the correspondence table in the pathlib docs, but that's easy to overlook when looking up ``pathlib.Path.replace``.

If nothing else, I guess this is a request to alter the docstring.
Date User Action Args
2022-04-11 14:59:29adminsetgithub: 84459
2020-04-14 04:45:59seliksetmessages: + msg366365
2020-04-14 04:10:34xtreaksetnosy: + docs@python, serhiy.storchaka, xtreak, pitrou
messages: + msg366364

assignee: docs@python
components: + Documentation
2020-04-14 03:36:59selikcreate