You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unclear documentation for shutil.copytree() #88513
"dirs_exist_ok dictates whether to raise an exception in case dst or any
missing parent directory already exists."
How can a "missing parent directory already exist"?
My understanding would be that an existing dst would be OK (and copied into) but missing parent directories are just the ones above dst that also don't exist.
Until 3.7, missing parent directories were documented to be auto-created (mkdir -p-style) according to the documentation ("The destination directory, named by dst, must not already exist; it will be created as well as missing parent directories."). Was this feature really removed? If not, then this part was accidentally (?) dropped from documentation?
What am I missing? I think, the documentation should be amended to make that clear.
Activity
tilmanvogel commentedon Jun 8, 2021
I donot understand this sentence:
"dirs_exist_ok dictates whether to raise an exception in case dst or any
missing parent directory already exists."
How can a "missing parent directory already exist"?
My understanding would be that an existing
dstwould be OK (and copied into) but missing parent directories are just the ones abovedstthat also don't exist.Until 3.7, missing parent directories were documented to be auto-created (
mkdir -p-style) according to the documentation ("The destination directory, named by dst, must not already exist; it will be created as well as missing parent directories."). Was this feature really removed? If not, then this part was accidentally (?) dropped from documentation?What am I missing? I think, the documentation should be amended to make that clear.
iritkatriel commentedon Jun 9, 2021
From the code, this arg is simply passed to os.mkdirs() here:
cpython/Lib/shutil.py
Line 450 in e6e34e4
os.mkdir is documented here: https://docs.python.org/3/library/os.html#os.makedirs
and says just "If exist_ok is False (the default), an FileExistsError is raised if the target directory already exists."
So I agree that the sentence you highlighted can be improved.
Would you like to submit a patch?
2 remaining items
jdevries3133 commentedon Jun 9, 2021
I would like to submit a patch for this. This would be my first contribution :)
I am starting on a patch now.
jdevries3133 commentedon Jun 9, 2021
I've created a PR: #26634
I forgot to put a news entry, but hopefully that's ok since this is a very small change.
gh-88513: clarify shutil.copytree's dirs_exist_ok arg (GH-91434)
pythongh-88513: clarify shutil.copytree's dirs_exist_ok arg (pythonGH…
JelleZijlstra commentedon Apr 12, 2022
#91434 was merged to address this. Thanks for your contribution @jdevries3133! I'll close this issue once the backports (#91464, #91465) are merged.
gh-88513: clarify shutil.copytree's dirs_exist_ok arg (GH-91434) (GH-…
gh-88513: clarify shutil.copytree's dirs_exist_ok arg (GH-91434) (GH-…
pythongh-88513: clarify shutil.copytree's dirs_exist_ok arg (pythonGH…