[New-bugs-announce] [issue35216] misleading error message from shutil.copy()
Cédric Van Rompay
report at bugs.python.org
Mon Nov 12 07:19:11 EST 2018
New submission from Cédric Van Rompay <cedric.vanrompay at gmail.com>:
When calling `shutil.copy('file.txt', 'not_here/')`,
if directory `not_here/` does not exist,
the raised error is:
IsADirectoryError: [Errno 21] Is a directory: 'not_here/'
If the intent of the user was to copy a file in a directory
but the user forgot to create the destination directory,
this can be very misleading,
as the error tends to indicate that the directory exists.
It happened to me and I was thinking
"yes it's a directory, then what?
that's exactly what I want,copy to this directory!"
when the problem was that I forgot to create the destination directory.
I would suggest to catch the `IsADirectoryError`
in shutil.copyfile() (at `open(dst, 'wb')`)
and raise instead an error saying something like
"destination is a directory AND this directory does not exists".
----------
components: Library (Lib)
messages: 329728
nosy: cedricvanrompay
priority: normal
severity: normal
status: open
title: misleading error message from shutil.copy()
type: behavior
versions: Python 3.6
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35216>
_______________________________________
More information about the New-bugs-announce
mailing list