X Tutup
The Wayback Machine - https://web.archive.org/web/20240110155314/https://github.com/python/cpython/issues/113803
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

inaccurate documentation for shutil.move when dst is an existing directory #113803

Open
daiwt opened this issue Jan 8, 2024 · 1 comment
Open
Labels
docs Documentation in the Doc dir easy

Comments

@daiwt
Copy link

daiwt commented Jan 8, 2024

Documentation

(A clear and concise description of the issue.)

In the doc of shutil it says:

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.

However, before calling os.rename, it checks the existence of the destination path, and raises Error if it exists. see shutil.py.

This behavior is not described in the documentation, and may be different from how files are overwritten in os.rename. For example, os.rename('a.txt', '/b') will silently replace /b/a.txt on Unix, but shutil.move('a.txt', '/b') will raise an Error.

In the docstring however, this is described much more clear:

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 the destination already exists but is not a directory, it may be
overwritten depending on os.rename() semantics.

This should be also in the documentation, IMO.

Linked PRs

@daiwt daiwt added the docs Documentation in the Doc dir label Jan 8, 2024
@serhiy-storchaka
Copy link
Member

Agree. Do you mind to create a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir easy
Projects
None yet
Development

No branches or pull requests

2 participants
X Tutup