It seems to me that os.removedirs() and os.renames() was added just for symmetry with os.makedirs(). All three functions have similar structure and was added in the same commit. Seems they were initially code examples of using some os.path and os functions.

Unlike to quite popular os.makedirs(), os.removedirs() and os.renames() are not used in the stdlib and rarely used in third party code. os.removedirs() is considered as an opposite to os.makedirs(), and os.renames() is a combination of os.makedirs(), os.rename() and os.removedirs(). The problems with them are:

1. They do not remove directory if any file or other subdirectory is left. They just stop removing and return success. ZTo the user it looks like they do not work as expected, but he need to test the existence of directory explicitly to check this.

2. They can remove more than expected. If the parent directory was empty before calling os.makedirs(), the following os.removedirs() will remove not just the newly created directories, but the parent directory, and its parent if it contained a single directory, and so on.

os.removedirs() is not an opposite to os.makedirs(). It can remove less or more, and you have no control on how much it will remove. It is better to use shutil.rmtree().

os.renames() correspondingly can be replaced by os.rename() or shutil.move(), with possible addition of os.makedirs() and shutil.rmtree() if needed.

I propose to deprecate these functions and remove them in future Python versions.
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/MWUFGKT43L3KJXN33DLTYN6OLDB6GP45/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to