[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 da8f9fb2ea)

Co-authored-by: Dai Wentao <dwt136@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-02-04 20:00:03 +01:00 committed by GitHub
parent b9937a6f22
commit 5d2e30958a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 16 deletions

View file

@ -354,21 +354,24 @@ Directory and files operations
.. function:: move(src, dst, copy_function=copy2) .. function:: move(src, dst, copy_function=copy2)
Recursively move a file or directory (*src*) to another location (*dst*) Recursively move a file or directory (*src*) to another location and return
and return the destination. the destination.
If the destination is an existing directory, then *src* is moved inside that If *dst* is an existing directory or a symlink to a directory, then *src*
directory. If the destination already exists but is not a directory, it may is moved inside that directory. The destination path in that directory must
be overwritten depending on :func:`os.rename` semantics. 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 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 used. Otherwise, *src* is copied to the destination using *copy_function*
removed. In case of symlinks, a new symlink pointing to the target of *src* and then removed. In case of symlinks, a new symlink pointing to the target
will be created in or as *dst* and *src* will be removed. 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 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 *src* and the destination, and will be used to copy *src* to the destination
:func:`os.rename` cannot be used. If the source is a directory, if :func:`os.rename` cannot be used. If the source is a directory,
:func:`copytree` is called, passing it the *copy_function*. The :func:`copytree` is called, passing it the *copy_function*. The
default *copy_function* is :func:`copy2`. Using :func:`~shutil.copy` as 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 *copy_function* allows the move to succeed when it is not possible to also

View file

@ -846,12 +846,12 @@ def move(src, dst, copy_function=copy2):
similar to the Unix "mv" command. Return the file or directory's similar to the Unix "mv" command. Return the file or directory's
destination. destination.
If the destination is a directory or a symlink to a directory, the source If dst is an existing directory or a symlink to a directory, then src is
is moved inside the directory. The destination path must not already moved inside that directory. The destination path in that directory must
exist. not already exist.
If the destination already exists but is not a directory, it may be If dst already exists but is not a directory, it may be overwritten
overwritten depending on os.rename() semantics. depending on os.rename() semantics.
If the destination is on our current filesystem, then rename() is used. If the destination is on our current filesystem, then rename() is used.
Otherwise, src is copied to the destination and then removed. Symlinks are Otherwise, src is copied to the destination and then removed. Symlinks are