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.

classification
Title: Broken docs for os.removedirs
Type: Stage:
Components: None Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: d_kagedal, effbot, georg.brandl
Priority: low Keywords:

Created on 2005-10-31 11:30 by d_kagedal, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
msg26766 - (view) Author: David Kågedal (d_kagedal) Date: 2005-10-31 11:30
The documentation for the os.removedirs function is
seriously broken.  This is from the library reference:

"removedirs(path)
    Removes directories recursively. Works like rmdir()
except that, if the leaf directory is successfully
removed, directories corresponding to rightmost path
segments will be pruned way until either the whole path
is consumed or an error is raised (which is ignored,
because it generally means that a parent directory is
not empty). Throws an error exception if the leaf
directory could not be successfully removed. New in
version 1.5.2."

The first sentence is the only part that makes any
sense. This shorter version contains as much
information and less misinformation"

"removedirs(path)
   Removes a directory and everything in it
recursively. If a file couldn't be removed, the removal
is aborted and you might get an exception if you're lucky."

The doc string you get when you type
"help(os.removedirs)" is different from the one in the
library reference, but equally broken.
msg26767 - (view) Author: Fredrik Lundh (effbot) * (Python committer) Date: 2005-11-12 15:49
Logged In: YES 
user_id=38376

Are you sure you understand how the function works?

Given "spam/egg/bacon", it first attempts to do an rmdir on
spam/egg/bacon.  If that fails, the function raises an
exception.  Otherwise, it proceeds to rmdir spam/egg and
spam. Errors during the latter stage are ignored.

If you want to remove directories whether they're empty or
not, use shutil.rmtree.
msg26768 - (view) Author: Fredrik Lundh (effbot) * (Python committer) Date: 2005-11-12 15:54
Logged In: YES 
user_id=38376

(I've changed the docstring from "remove a leaf directory and
empty all intermediate ones" to "remove a leaf directory and
all empty intermediate ones".  both the docstring and the docs
could need some clarification, but the text you propose is not
really an improvement...)
msg26769 - (view) Author: David Kågedal (d_kagedal) Date: 2005-11-13 21:11
Logged In: YES 
user_id=1260741

> Are you sure you understand how the function works?

No I'm not.  But that's the whole point of this bug report.
 Reading the documentation didn't help.

Saying "Removes directories recursively" means something
different to me than what you describe, so I think it's easy
to mislead already there.

When it sans that "rightmost path segments will be pruned
away", that doesn't tell me that anything will be removed
from the file system, does it?

My suggestion for new doc string wasn't meant to be
accepted, but more to describe what information the original
contained.

How about this then:

  Removes the given directory, just like rmdir().  In
addition, if the removal was successful, the parent
directories mentioned in the 'path' argument are removed if
they are now empty.  This is done by removing the last path
segment from the given path and trying to remove the
directory given by the remaining path, until there is
nothing left of the original path string.  No exception will
be raised while trying to remove parent directories.
msg26770 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-12-17 17:31
Logged In: YES 
user_id=1188172

Fixed the docs in rev. 41734/41735.
History
Date User Action Args
2022-04-11 14:56:13adminsetgithub: 42537
2005-10-31 11:30:59d_kagedalcreate