[issue42929] On Windows, shutil.move doesn't raise FileExistsError if dst exists like os.rename

fireattack report at bugs.python.org
Thu Jan 14 16:29:10 EST 2021


New submission from fireattack <human.peng at gmail.com>:

According to https://docs.python.org/3.8/library/shutil.html#shutil.move

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

I interpret "depending on os.rename() semantics" to mean it will follow os.rename()'s behavior.

According to https://docs.python.org/3/library/os.html#os.rename

"On Windows, if dst exists a FileExistsError is always raised."

However, their behaviors are not the same.

For os.rename, it does raise FileExistsError if dst exists.
For shutil.move, it silently overwrites dst.

It's either a bug in behavior of shutil.move, or the documentation need to be updated.

----------
components: Library (Lib)
messages: 385083
nosy: fireattack
priority: normal
severity: normal
status: open
title: On Windows, shutil.move doesn't raise FileExistsError if dst exists like os.rename
type: behavior
versions: Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42929>
_______________________________________


More information about the Python-bugs-list mailing list