From 8bfe6ff048468d90d94273ce0b807cd2157d24c1 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" <68491+gpshead@users.noreply.github.com> Date: Thu, 22 Oct 2026 16:12:35 -0700 Subject: [PATCH] gh-160322: document shutil.rmtree("link/") symlink following behavior (GH-160372) (cherry picked from commit 2c24bc1b6ea3fa135634db9d0c336d67b1d42ef9) Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com> --- Doc/library/shutil.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Doc/library/shutil.rst b/Doc/library/shutil.rst index 6febc7a187a15f8..369cd5e1a714814 100644 --- a/Doc/library/shutil.rst +++ b/Doc/library/shutil.rst @@ -313,6 +313,12 @@ Directory and files operations handled by calling a handler specified by *onexc* or *onerror* or, if both are omitted, exceptions are propagated to the caller. + If *path* is a symbolic link to a directory followed by a trailing path + separator, such as ``'link/'``, the operating system resolves the link, so + :func:`!rmtree` deletes the contents of the directory it points to and then + fails to remove *path* itself. :class:`pathlib.Path` strips trailing + separators, so ``rmtree(Path('link/'))`` refuses the link as usual. + This function can support :ref:`paths relative to directory descriptors `.