Repository navigation
gh-89721: Add copy_dir_stat parameter to shutil.copytree() - #160076
Merged
Merged
Conversation
copytree() now accepts copy_dir_stat (default true). When false, directory permissions and times are not copied with copystat(), e.g. to copy a read-only tree into a writable one. The flag propagates through recursive calls; file metadata is unaffected and remains handled by copy_function. Document the parameter and cover both behaviors with tests. Co-authored-by: Muse Code (Meta Muse Spark)
Documentation build overview
43 files changed ·
|
WASI cannot change file mode bits, so skip the new copytree mode tests there like the other chmod-dependent tests in test_shutil. Co-authored-by: Muse Code (Meta Muse Spark)
itamaro
approved these changes
Oct 22, 2026
itamaro
left a comment
Contributor
There was a problem hiding this comment.
does this need a whatsnew bullet too?
Make copy_dir_stat keyword-only (ignore_dangling_symlinks and dirs_exist_ok stay positional-or-keyword: they date back to 3.2 and 3.8). Convert the recursive calls accordingly. Document that copy_dir_stat=False alone does not make a read-only tree writable; file metadata stays with copy_function. Say "directory metadata" instead of the narrower "permissions and times". Assert directory mtimes are not copied either. Add a What's New entry. Co-authored-by: Muse Code (Meta Muse Spark)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #109717 (closed).
Adds a
copy_dir_statparameter (default true) toshutil.copytree(). When false, directory permissions and times are not copied withcopystat(), e.g. to copy a read-only tree into a writable one. Unlike the superseded PR, the flag propagates through recursive calls, and file metadata stays withcopy_function(documented). Includes tests, docs, and a news entry.