Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.11] gh-113803: Fix inaccurate documentation for shutil.move when dst is an existing directory (GH-113837) #115007

Merged
merged 1 commit into from Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 14 additions & 11 deletions Doc/library/shutil.rst
Expand Up @@ -348,21 +348,24 @@ Directory and files operations

.. function:: move(src, dst, copy_function=copy2)

Recursively move a file or directory (*src*) to another location (*dst*)
and return the destination.
Recursively move a file or directory (*src*) to another location and return
the destination.

If the destination is an existing directory, then *src* is moved inside that
directory. If the destination already exists but is not a directory, it may
be overwritten depending on :func:`os.rename` semantics.
If *dst* is an existing directory or a symlink to a directory, then *src*
is moved inside that directory. The destination path in that directory must
not already exist.

If *dst* already exists but is not a directory, it may be overwritten
depending on :func:`os.rename` semantics.

If the destination is on the current filesystem, then :func:`os.rename` is
used. Otherwise, *src* is copied to *dst* using *copy_function* and then
removed. In case of symlinks, a new symlink pointing to the target of *src*
will be created in or as *dst* and *src* will be removed.
used. Otherwise, *src* is copied to the destination using *copy_function*
and then removed. In case of symlinks, a new symlink pointing to the target
of *src* will be created as the destination and *src* will be removed.

If *copy_function* is given, it must be a callable that takes two arguments
*src* and *dst*, and will be used to copy *src* to *dst* if
:func:`os.rename` cannot be used. If the source is a directory,
If *copy_function* is given, it must be a callable that takes two arguments,
*src* and the destination, and will be used to copy *src* to the destination
if :func:`os.rename` cannot be used. If the source is a directory,
:func:`copytree` is called, passing it the *copy_function*. The
default *copy_function* is :func:`copy2`. Using :func:`~shutil.copy` as the
*copy_function* allows the move to succeed when it is not possible to also
Expand Down
10 changes: 5 additions & 5 deletions Lib/shutil.py
Expand Up @@ -813,12 +813,12 @@ def move(src, dst, copy_function=copy2):
similar to the Unix "mv" command. Return the file or directory's
destination.

If the destination is a directory or a symlink to a directory, the source
is moved inside the directory. The destination path must not already
exist.
If dst is an existing directory or a symlink to a directory, then src is
moved inside that directory. The destination path in that directory must
not already exist.

If the destination already exists but is not a directory, it may be
overwritten depending on os.rename() semantics.
If dst already exists but is not a directory, it may be overwritten
depending on os.rename() semantics.

If the destination is on our current filesystem, then rename() is used.
Otherwise, src is copied to the destination and then removed. Symlinks are
Expand Down