Skip to content

Commit da8f9fb

Browse files
authored
gh-113803: Fix inaccurate documentation for shutil.move when dst is an existing directory (#113837)
* fix the usage of dst and destination in shutil.move doc * update shutil.move doc
1 parent d466052 commit da8f9fb

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
@@ -360,21 +360,24 @@ Directory and files operations
360360

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

363-
Recursively move a file or directory (*src*) to another location (*dst*)
364-
and return the destination.
363+
Recursively move a file or directory (*src*) to another location and return
364+
the destination.
365365

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

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

375-
If *copy_function* is given, it must be a callable that takes two arguments
376-
*src* and *dst*, and will be used to copy *src* to *dst* if
377-
:func:`os.rename` cannot be used. If the source is a directory,
378+
If *copy_function* is given, it must be a callable that takes two arguments,
379+
*src* and the destination, and will be used to copy *src* to the destination
380+
if :func:`os.rename` cannot be used. If the source is a directory,
378381
:func:`copytree` is called, passing it the *copy_function*. The
379382
default *copy_function* is :func:`copy2`. Using :func:`~shutil.copy` as the
380383
*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
@@ -861,12 +861,12 @@ def move(src, dst, copy_function=copy2):
861861
similar to the Unix "mv" command. Return the file or directory's
862862
destination.
863863
864-
If the destination is a directory or a symlink to a directory, the source
865-
is moved inside the directory. The destination path must not already
866-
exist.
864+
If dst is an existing directory or a symlink to a directory, then src is
865+
moved inside that directory. The destination path in that directory must
866+
not already exist.
867867
868-
If the destination already exists but is not a directory, it may be
869-
overwritten depending on os.rename() semantics.
868+
If dst already exists but is not a directory, it may be overwritten
869+
depending on os.rename() semantics.
870870
871871
If the destination is on our current filesystem, then rename() is used.
872872
Otherwise, src is copied to the destination and then removed. Symlinks are

0 commit comments

Comments
 (0)