This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jerpint
Recipients jerpint
Date 2021-02-14.05:16:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Issue: If you try to copy a file to a directory that doesn't exist using shutil.copy, a IsADirectory error is raised saying the directory exists. 

This issue is actually caused when `open(not_a_dir, 'wb') is called on a non-existing dir.

Expected behaviour: Should instead raise NotADirectoryError

Steps to reproduce:

[nav] In [1]: import os
         ...: from pathlib import Path
         ...: from shutil import copy
         ...: tmp_file = '/tmp/some_file.txt'
         ...: Path(tmp_file).touch()
         ...: nonexistent_dir = 'not_a_dir/'
         ...: assert not os.path.exists(nonexistent_dir)
         ...: copy(tmp_file, nonexistent_dir)
IsADirectoryError                         Traceback (most recent call last)
<ipython-input-2-b0e0ec4f4875> in <module>
      7 nonexistent_dir = 'not_a_dir/'
      8 assert not os.path.exists(nonexistent_dir)
----> 9 copy(tmp_file, nonexistent_dir)

~/miniconda3/lib/python3.7/ in copy(src, dst, follow_symlinks)
    243     if os.path.isdir(dst):
    244         dst = os.path.join(dst, os.path.basename(src))
--> 245     copyfile(src, dst, follow_symlinks=follow_symlinks)
    246     copymode(src, dst, follow_symlinks=follow_symlinks)
    247     return dst

~/miniconda3/lib/python3.7/ in copyfile(src, dst, follow_symlinks)
    119     else:
    120         with open(src, 'rb') as fsrc:
--> 121             with open(dst, 'wb') as fdst:
    122                 copyfileobj(fsrc, fdst)
    123     return dst

IsADirectoryError: [Errno 21] Is a directory: 'not_a_dir/'
Date User Action Args
2021-02-14 05:16:28jerpintsetrecipients: + jerpint
2021-02-14 05:16:28jerpintsetmessageid: <>
2021-02-14 05:16:28jerpintlinkissue43219 messages
2021-02-14 05:16:28jerpintcreate