Skip to content

Commit 5d2e309

Browse files
[3.12] gh-113803: Fix inaccurate documentation for shutil.move when dst is an existing directory (GH-113837) (#115006)
* fix the usage of dst and destination in shutil.move doc * update shutil.move doc (cherry picked from commit da8f9fb) Co-authored-by: Dai Wentao <[email protected]>
1 parent b9937a6 commit 5d2e309

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

Doc/library/shutil.rst

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -354,21 +354,24 @@ Directory and files operations
354354

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

357-
Recursively move a file or directory (*src*) to another location (*dst*)
358-
and return the destination.
357+
Recursively move a file or directory (*src*) to another location and return
358+
the destination.
359359

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

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

369-
If *copy_function* is given, it must be a callable that takes two arguments
370-
*src* and *dst*, and will be used to copy *src* to *dst* if
371-
:func:`os.rename` cannot be used. If the source is a directory,
372+
If *copy_function* is given, it must be a callable that takes two arguments,
373+
*src* and the destination, and will be used to copy *src* to the destination
374+
if :func:`os.rename` cannot be used. If the source is a directory,
372375
:func:`copytree` is called, passing it the *copy_function*. The
373376
default *copy_function* is :func:`copy2`. Using :func:`~shutil.copy` as the
374377
*copy_function* allows the move to succeed when it is not possible to also

Lib/shutil.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -846,12 +846,12 @@ def move(src, dst, copy_function=copy2):
846846
similar to the Unix "mv" command. Return the file or directory's
847847
destination.
848848
849-
If the destination is a directory or a symlink to a directory, the source
850-
is moved inside the directory. The destination path must not already
851-
exist.
849+
If dst is an existing directory or a symlink to a directory, then src is
850+
moved inside that directory. The destination path in that directory must
851+
not already exist.
852852
853-
If the destination already exists but is not a directory, it may be
854-
overwritten depending on os.rename() semantics.
853+
If dst already exists but is not a directory, it may be overwritten
854+
depending on os.rename() semantics.
855855
856856
If the destination is on our current filesystem, then rename() is used.
857857
Otherwise, src is copied to the destination and then removed. Symlinks are

0 commit comments

Comments
 (0)